Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Google Maps Directions via an intent on Android

My app needs to show Google Maps directions from A to B, but I don't want to put the Google Maps into my application - instead, I want to launch it using an Intent. Is this possible? If yes, how?

like image 911
Lars D Avatar asked Apr 18 '10 14:04

Lars D


People also ask

How do I open a Google map with intent?

ACTION_VIEW, Uri. parse("geo:0,0? q=replace+this+with+an+address")); startActivity(intent); This Android code snippet will launch the google map with direction to the address you passed in.

Is it possible to embed Google navigation in an Android app?

Short answer: Yes (with a but). If you are asking about displaying a full Navigation experience with turn by turn instructions, a puck, routines on Google Maps, then the answer is: It's illegal to do it without Google's permission.

How do I show Google Maps automatically on Android?

To fix this, all you need to do is go to Device Care on your Samsung smartphone and check out the settings for Google Maps. Someone on Google's discussion board explains that going into the app info screen and enabling Google Maps brought things back to normal, with the app's icon once again showing up on Android Auto.


1 Answers

You could use something like this:

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 the navigation from the current location, remove the saddr parameter and value.

You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.

This will fire up Google Maps in navigation mode directly:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,     Uri.parse("google.navigation:q=an+address+city")); 

UPDATE

In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:

https://developers.google.com/maps/documentation/urls/guide

You can use Intents with the new API as well.

like image 159
Jan S. Avatar answered Sep 19 '22 05:09

Jan S.