通过多个航点了解Google导航行程

Non*_*ney 9 android google-maps android-intent google-maps-urls

我想知道,如果可以在"Google导航"(Google地图导航)中放置几个​​"检查点",则查询遵循下一个语法: "google.navigation:q=44.871709,-0.505704...."

如果可能的话,单独两点的语法是什么?

有一点可行,例如: "google.navigation:q=44.871709,-0.505704"

但我会举几个检查点,例如:

 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));  
Run Code Online (Sandbox Code Playgroud)

我读了其他问题,他们说使用这种语法:

"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
Run Code Online (Sandbox Code Playgroud)

有了上述解决方案,"谷歌导航"不会自动启动,我们必须选择一个应用程序"谷歌地图",然后点击行程(在屏幕顶部)启动"谷歌导航".如果可能的话我想避免它.

kus*_*yar 17

这是一种压制对话框并直接转到地图的方法.

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);
Run Code Online (Sandbox Code Playgroud)

如果您还有问题,请告诉我.

UPDATE

截至2017年5月,有一种更好的方法,Google Maps URL API

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

使用此API,您可以构建包含origin,destination和waypoints的URL,并将其传递给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); 
Run Code Online (Sandbox Code Playgroud)