Maxim Neaga
Maxim Neaga

Reputation: 961

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

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?

enter image description here

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");

Upvotes: 0

Views: 8105

Answers (2)

Jason Maderski
Jason Maderski

Reputation: 76

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);

Upvotes: 6

xomena
xomena

Reputation: 32178

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!

Upvotes: 3

Related Questions