Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent to Google Navigation for itinerary with several waypoints

I want to know, if it's possible to put several "checkpoints" within "Google Navigation" (Google Maps Navigation) With a query that follows the next syntax : "google.navigation:q=44.871709,-0.505704...."

If it possible, what is the syntax for separate two points ?

For one point it works, example : "google.navigation:q=44.871709,-0.505704"

But I would put a few checkpoints for example :

 LatLng point1 = new LatLng(44.871709,-0.505704);
 LatLng point2 = new LatLng(43.572665,3.871447);                    
 Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+
 point1.latitude+","+point1.longitude+";"+ point2.latitude+","+point2.longitude));  

I read others issues, they say to use this syntax :

"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"

With above solution, "Google Navigation" is not started automatically, we must choose one application "Google Maps" and next, to click on Itinerary (in top of the screen) to start "Google Navigation". I would like to avoid it if possible.

like image 912
NonowPoney Avatar asked May 23 '13 15:05

NonowPoney


People also ask

Can you set waypoints in Google Maps?

Google is rolling out a clever new feature on its Maps app for Android, which lets you add multiple waypoints en route to your destination for easier navigation.


2 Answers

Here is a way to supress the dialog and go to maps directly.

String uri = "http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447";
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);

Let me know if you still have issues.

UPDATE

As of May 2017, there is a better approach, the Google Maps URLs API

https://developers.google.com/maps/documentation/urls/guide

Using this API you can construct an URL with origin, destination and waypoints and pass it to the intent

String uri = "https://www.google.com/maps/dir/?api=1&origin=Madrid,Spain&destination=Barcelona,Spain&waypoints=Zaragoza,Spain%7CHuesca,Spain&travelmode=driving&dir_action=navigate";
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); 
like image 86
kushyar Avatar answered Sep 16 '22 20:09

kushyar


Check these 2 methods, both of them work properly for me.

METHOD 1:

    String packageName = "com.google.android.apps.maps";
    String query = "google.navigation:q=49.4839509,8.4903999";

    Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(query));
    startActivity(intent);

METHOD 2:

    String packageName = "com.google.android.apps.maps";
    String query = "google.navigation:q=49.4839509,8.4903999";

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
    intent.setPackage(packageName);
    startActivity(intent);
like image 22
Ayaz Alifov Avatar answered Sep 17 '22 20:09

Ayaz Alifov