Launching Google Maps Directions with Intents for Android
Question:
How can I launch Google Maps directions between two locations using an Intent in an Android app?
Answer:
Yes, it is possible to use an Intent to launch Google Maps directions. Here's how you can do it:
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);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=20.5666,45.345")); startActivity(intent);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=an+address+city"));
Update (May 2017):
Google has launched a new API for universal, cross-platform Google Maps URLs. You can use Intents with the new API as well:
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=Sydney&destination=Brisbane&travelmode=driving");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, gmmIntentUri); startActivity(intent);
The above is the detailed content of How to Launch Google Maps Directions Using Intents in Android?. For more information, please follow other related articles on the PHP Chinese website!