简体   繁体   中英

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

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

使用Google Direction API,您可以轻松集成Google Map Direction API,请点击以下链接-https://www.journaldev.com/13373/android-google-map-drawing-route-two-points

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM