Home >Java >javaTutorial >How Can I Launch Google Maps Directions Using an Android Intent?
Launching External Google Maps Directions with an Intent
To launch external Google Maps directions without embedding the Google Maps application within your own, an Intent can be employed.
Implementation:
To launch Google Maps directions from point A to B using an Intent, the following approach can be used:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345")); startActivity(intent);
If you want to start navigation from the current location, simply remove the "saddr" parameter and its associated value.
Using Street Addresses:
Instead of latitude and longitude, you can specify actual street addresses. However, this approach presents the user with a dialog to choose between opening the directions in a browser or Google Maps.
Direct Navigation Mode:
To directly initiate Google Maps navigation mode, the following Intent can be utilized:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=an+address+city"));
Google Maps API Updates (May 2017):
In May 2017, Google introduced a new API for cross-platform Google Maps URLs. This API can also be used alongside Intents to launch Google Maps directions. For further information, refer to the Google Maps URLs guide:
https://developers.google.com/maps/documentation/urls/guide
The above is the detailed content of How Can I Launch Google Maps Directions Using an Android Intent?. For more information, please follow other related articles on the PHP Chinese website!