Destination Google Navigation for a route with multiple waypoints

I want to know if it’s possible to put several “checkpoints” in “Google Navigation” (Navigation on Google Maps) with a query that follows the following syntax: "google.navigation:q=44.871709,-0.505704...."

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

At one point this works, for example: "google.navigation:q=44.871709,-0.505704"

But I would put a few control points, 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 other issues, they say they use this syntax:

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

With the above solution, “Google Navigation” does not start automatically, we must select one “Google Maps” application, and then click “Route” (at the top of the screen) to start “Google Navigation”. I would like to avoid this if possible.

+6
source share
4 answers

Here's a way to suppress the dialogue and go directly to the cards.

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

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 create a URL indicating the source, destination and waypoints and pass it on 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); 
+10
source

Check out these 2 methods, both of them work correctly 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); 
+3
source

Since point1.longitude Double, you should use this

 String.valueOf(point1.latitude); Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+String.valueOf(point1.latitude)+","+String.valueOf(point1.longitude)+";"+String.valueOf( point2.latitude)+","+String.valueOf(point2.longitude))); 

Or you can use it, but anyway.

 point1.toString().replace("lat/lng: (", "").replace(")", "") 

point1.toString () result: "lat / lng: (44.871709, -0.505704)", delete "lat / lng: (" and ")". then you can get the result you want.

 Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", ""))); 

Or you can try this

 Uri uri = Uri.parse("http://maps.google.com/mapssaddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", "")); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 

Hope this helps you.

0
source

You just need to transfer the destination. The Google Maps app will automatically display your current location for navigation.

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + String.valueOf(destination latitude) + "," + String.valueOf(destination longitude))); startActivity(intent); 
-1
source

Source: https://habr.com/ru/post/945690/


All Articles