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
Release: 2024-12-14 07:23:29
Original
430 people have browsed it

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);
Copy after login
  • 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);
Copy after login
  • 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"));
Copy after login

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");
Copy after login
  • Create Intent:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, gmmIntentUri);
startActivity(intent);
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template