Android, how to pass lat long route info to Google Maps App

MHugh picture MHugh · Mar 8, 2017 · Viewed 13.1k times · Source

I have an Android app which shows a number of locations on a Map. When I click on a location I would like to pass the lat long of the location, and the lat long of the device's location, to the Google Maps App so that it can show me route information between the two.

Is this possible? If so how? Thanks.

Answer

WannaBeGeek picture WannaBeGeek · Aug 7, 2017

Yes, You can pass lat and lng to the Maps , and show directions to that Place using the Android Intent.

Directions are always given from the users current location.

Following query will help you perform that . You can pass the destination latitude and longitude here:

google.navigation:q=latitude,longitude

Use above as:

Uri gmmIntentUri = Uri.parse("google.navigation:q=latitude,longitude");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

More Info here: https://developers.google.com/maps/documentation/urls/android-intents