Home > Java > javaTutorial > How Can I Launch Google Maps Directions Using an Android Intent?

How Can I Launch Google Maps Directions Using an Android Intent?

Mary-Kate Olsen
Release: 2024-12-20 13:50:10
Original
638 people have browsed it

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

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

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!

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