14

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)

Santhosh
  • 4,956
  • 12
  • 62
  • 90
  • 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 Oct 27 '17 at 11:30
  • Did you enable "Don't keep activities" in DeveloperOptions settings screen? It should be disabled always. Otherwise, you may end up such issues. – Santhosh Oct 27 '17 at 11:43
  • @Santosh, thank you for your suggestion. – basha Oct 30 '17 at 04:29
  • @Basha : Did it solve your problem ? – Santhosh Oct 30 '17 at 05:38
  • no, it worked for some time. Don't keep Activities is in the off position. again now same issue continuing man. – basha Oct 30 '17 at 07:30

1 Answers1

31

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

Community
  • 1
  • 1
rahulserver
  • 10,411
  • 24
  • 90
  • 164
  • The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. But not for showing the map. Thanks anyways. – Santhosh Jul 16 '13 at 09:26
  • I want to invoke google maps app to show the road map between two locations. The current url is showing only walking directions between the locations. How can I show the other modes like driving, transit etc? – Santhosh Jul 16 '13 at 10:05
  • @rahulserver Nice answer,But it show all possible path.Is there any way so i can directly open shortest path,without giving all paths listing. – Ravi Bhandari Feb 02 '15 at 05:44
  • Is it possible to start google maps to give directions using my current location and give directions by passing only targetLat and targetLan?, I mean, avoiding get my current location with code – Robert Jul 17 '15 at 21:36
  • How would you avoid all highways, tolls, and ferries with driving directions enabled? – CopsOnRoad Feb 11 '18 at 17:11