简体   繁体   中英

How to get direction navigation in Google maps in android

I want to show navigation direction while clicking the info window.

I tried some code, it shows the Preview button, but it does not show the navigation button.

I got it like in the picture below: 注意预览图标下方

But, I want it like this:

Here my code:

 final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" +
            "saddr="+ gps.latitude + "," + gps.longitude + "&daddr=" + marker.getPosition().latitude + "," +
            marker.getPosition().longitude+ "&sensor=false&units=metric&mode=driving"));
            intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
            startActivity(intent);

You can follow this documentation on how to launch Google Maps navigation with turn-by-turn directions to the address or coordinate specified.

Here is a sample Intent which requests turn-by-turn navigation to Taronga Zoo, in Sydney Australia:

Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

Check these related SO threads:

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