Home >Java >javaTutorial >How to Launch Google Maps Directions Using Intents in Android?

How to Launch Google Maps Directions Using Intents in Android?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-14 07:23:29497browse

How to Launch Google Maps Directions Using Intents in Android?

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:

  • From Latitudes and Longitudes:
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);
  • From Current Location:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?daddr=20.5666,45.345"));
startActivity(intent);
  • Direct Navigation (requires Google Maps app to be installed):
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:

  • Parse Google Maps URL:
Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=Sydney&destination=Brisbane&travelmode=driving");
  • Create Intent:
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn