-1

I'm working on an android app in Android Studio, and when a user hits a button, I want to launch the built-in google maps app on the android device. I would also like the map to display a given destination (which is from my own app) in the directions portion of the google maps app. Does anyone know how to go about this?

kb4593
  • 1
  • 2

1 Answers1

1

You can use this code to achieve this.

String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving";
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);

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 to this SO post answer for more details.

Community
  • 1
  • 1
David Passmore
  • 6,089
  • 4
  • 46
  • 70