Android - How to launch Google map intent in driving mode?

别等时光非礼了梦想. 提交于 2019-11-26 23:35:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!