0

Good day,

I am trying to use Google maps to navigate my app user to a certain address / location. From what I have found on the net so far I have tried the following:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?saddr=-36.181,27.949&daddr=-36.174732,27.949770"));
                    startActivity(intent);

Now this is all good and well it opens up Google maps, but it ask me a jolly lot of things before I can actually get to the navigation.

  • 1: It fist asks me to select a trip
  • 2: It then shows me the trip
  • 3: I then have to click the little arrow head (Navigate Button)

Then only does it begin Navigation.

Is there not a way for me to specify in my intent to use the first route and to just start navigating immediately/automatically?

On a second note, Once I have reached my destination or I want to go back/cancel, the back button needs to take me back to my application, right now it then goes back to showing me the route, then I click back again and it says are you sure you want to exit navigation.

Or can I maybe listen for an Intent that Maps publishes once you have reached the destination. So as The user gets to the destination my application will come into focus again?

Zapnologica
  • 22,170
  • 44
  • 158
  • 253

3 Answers3

3

Try this method

String urlAddress = "http://maps.google.com/maps?q="+ lat + ","+ lng + "("
                + your_location_name + ")&iwloc=A&hl=es";
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(urlAddress));
        startActivity(intent);

This will open the google map on given valid lat, lng values and will show your_location_name as the place name.

Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
1
// try this way,hope this will help you to solve your problem.

String uri = "http://maps.google.com/maps?f=d&hl=es&saddr=-36.181,27.949&daddr=-36.174732,27.949770";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String                  .format(Locale.US, uri, customerDropOffLatLng.latitude, customerDropOffLatLng.longitude)));
navIntent.setPackage("com.google.android.apps.maps");
startActivity(navIntent);
Davis Broda
  • 4,102
  • 5
  • 23
  • 37
parvesh
  • 1
  • 1
  • Welcome to SO. Please refrain from code only answers; provide some context/explanation. See https://stackoverflow.com/help/how-to-answer – Uwe Allner Jul 25 '17 at 12:18