Home >Java >javaTutorial >How to Launch Google Maps Directions from Your Android App Using Intents?
Launching Google Maps Directions with Android Intents
Need to display Google Maps directions from one location to another within your Android app without incorporating the entire map framework? Using intents makes it achievable.
How to Launch Google Maps Directions with Intents:
To launch Google Maps directions using intents, follow these steps:
Example using coordinates:
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);
To start navigation from the current location, omit the saddr parameter.
Note: Using street addresses instead of coordinates will present the user with a choice between opening in a browser or Google Maps.
To launch Google Maps navigation directly:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=an+address+city"));
Google Maps Intents in 2023
In May 2017, Google introduced a new API that supports universal Google Maps URLs. You can leverage this API with intents as well:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("https://www.google.com/maps/dir/?api=1&origin=source_location&destination=destination_location"));
Note: Replace source_location and destination_location with the appropriate values.
The above is the detailed content of How to Launch Google Maps Directions from Your Android App Using Intents?. For more information, please follow other related articles on the PHP Chinese website!