问题
I am able to launch Google Maps intent with
Uri location = Uri.parse("geo:0,0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
startActivity(mapIntent);
How can I launch the intent in Driving mode (with no destination, unless previously set in Maps) so that it looks like on the screenshot below?
I tried setting mode=driving
but that just opens the regular map with the "driving" tab selected:
Uri location = Uri.parse("geo:0,0?mode=driving");
回答1:
This will launch google maps in Driving Mode
Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.maps");
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("google.navigation:/?free=1&mode=d&entry=fnls"));
startActivity(intent);
回答2:
I understand you would like to open a Google Maps app in navigation mode. For this purpose you can use an URL described in the Google Maps URLs API:
https://developers.google.com/maps/documentation/urls/guide#directions-action
The following code should do a trick, and I believe you need to provide a destination parameter to open this mode directly
String URL = "https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=Los+Angeles";
Uri location = Uri.parse(URL);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);
startActivity(mapIntent);
I hope this helps!
来源:https://stackoverflow.com/questions/44249206/android-how-to-launch-google-map-intent-in-driving-mode