Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 435
Santhosh Avatar asked Jul 16 '13 08:07

Santhosh


People also ask

How do I use Google Directions API on Android?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.


1 Answers

"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.

like image 142
rahulserver Avatar answered Sep 20 '22 16:09

rahulserver