Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Google maps app with directions by coordinates

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...

like image 352
archer Avatar asked Mar 07 '23 03:03

archer


1 Answers

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

like image 198
Amardeep Avatar answered Mar 14 '23 20:03

Amardeep