Open Google maps app with directions by coordinates

archer picture archer · Jan 12, 2018 · Viewed 9.4k times · Source

I'm coding an app (both iOS and Android) that should be able to open the Google Maps app on the device and give directions to a target. The target is provided as latitude/longitude coordinates. I have read the official guid how to do this (https://developers.google.com/maps/documentation/urls/guide) but it still doesn't work.

Below is an example of an url that I send from my app. If I paste that same url into a browser on my computer, it works fine, but if I try to open it on my device I get an error message that says "Unsupported link, Google Maps can't open this link".

https://www.google.com/maps/dir/?api=1&destination=50.693907573202%2C10.970328366756

What am I doing wrong?

EDIT: I noticed that it works the second time i send the url, but never the first. In other words: in my app, I touch the "Directions" button and Google Maps is displayed with the error message. I then return to my app and press the "Directions" button again and it works. Why does it not work the first time? Does Google Maps need to be running in the background for it to work? There is no mention of this in the docs...

Answer

Amardeep picture Amardeep · Jan 12, 2018

You have to use this to start navigation on mobile plateform.

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

For futher reading https://developers.google.com/maps/documentation/urls/android-intents