14
votes

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)

2
did you get your application back, when you press back button in google maps . I used same intent to go to android Maps from my application. but when I press back button ,my Application was finishing. how can you overcome this issue ? - basha
Did you enable "Don't keep activities" in DeveloperOptions settings screen? It should be disabled always. Otherwise, you may end up such issues. - Santhosh
@Santosh, thank you for your suggestion. - basha
@Basha : Did it solve your problem ? - Santhosh
no, it worked for some time. Don't keep Activities is in the off position. again now same issue continuing man. - basha

2 Answers

30
votes

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

5
votes
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);