Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple way points in Google Maps via Android Intent

As a part of navigation in my app, I am re-directing my app to Google Maps along with the lats and longs. I have already succeeded in passing the source and destination and making it open in Google Maps directly.

Uri gmmIntentUri = Uri.parse("google.navigation:q=9.883456,78.120150");
Intent mapIntent = new Intent(Intent.ACTION_VIEW,gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

But my question is how do I pass multiple points to Google Maps via intent. Recently Google introduced adding multiple destinations in the mobile version of the Google Map app and I presume that its available in the Google Directions API but I don't want to take the twisted path by integrating Google Directions in my app, I'd rather take the highway to Google Maps.

I have been searching a lot on this topic but all I find is the following but that doesnt work either.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=st.%20louis,mo&daddr=washington,dc%20to:chicago,il%20to:new%20york,ny"));
startActivity(intent);

The above code works only when we open it in Chrome but I want it to open in Google Maps and even adding a mapIntent.setPackage("com.google.android.apps.maps"); doesn't work but its kinda obvious that the above uri passed is a URL that's available in Google Maps of web version.

Any insights or any ideas on how this can be achieved will be more than welcomed.

P.S: Can this be achieved at all ?????

like image 223
San Avatar asked Jul 14 '16 12:07

San


1 Answers

  1. Contruct URL = https://www.google.co.in/maps/dir/18.6121132,73.707989/18.642344,73.707880/18.652344,73.727880/18.6530132,73.7270

    In above URL

    source = 18.6121132,73.707989

    waypoint1 = 18.642344,73.707880

    waypoint2 = 18.652344,73.727880

    destination = 18.6530132,73.7270

  2. Call Google Map Intent URI

    Uri gmmIntentUri = Uri.parse("https://www.google.co.in/maps/dir/18.6121132,73.707989/18.5,73.7/18.8,73.71"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); startActivity(mapIntent);

I have tested it with multiple way points and it worked for me. I hope this will help others

Note: It works only on latest Android Google Maps application

like image 169
Sachin Suryavanshi Avatar answered Sep 20 '22 23:09

Sachin Suryavanshi