Santhosh
Santhosh

Reputation: 5016

Launch google maps application for driving directions in android

Here is how I'm launching native google maps app to show the directions between my & target locations.

String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

Is there any way to launch native maps app to show driving and transit modes? (Currently its showing only walking directions)

Upvotes: 14

Views: 20508

Answers (1)

rahulserver
rahulserver

Reputation: 11205

"Is there any way to launch native maps app to show driving and transit modes? (Currently its showing only walking directions)" yes.

Just specify the travel modes in the url.

Use url like this for example to specify driving as your travel mode

String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving";

Rest of code remains the same.

You can use the dirflg parameter as:

dirflg=h - Switches on "Avoid Highways" route finding mode.
dirflg=t - Switches on "Avoid Tolls" route finding mode.
dirflg=r - Switches on "Public Transit" - only works in some areas.
dirflg=w - Switches to walking directions - still in beta.
dirflg=d - Switches to driving directions

Refer this SO post answer.

Upvotes: 31

Related Questions