我想知道,是否可以在“Google 导航”(Google map 导航)中放置几个“检查点”,查询遵循以下语法:"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));
我读过其他问题,他们说要使用这种语法:
"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
使用上述解决方案,“Google Navigation”不会自动启动,我们必须选择一个应用程序“Google Maps”,然后单击 Itinerary(在屏幕顶部)以启动“Google Navigation”。 如果可能的话,我想避免它。
最佳答案
这是一种抑制对话框并直接转到 map 的方法。
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);
如果您还有问题,请告诉我。
更新
截至 2017 年 5 月,有一种更好的方法,即 Google Maps URLs API
https://developers.google.com/maps/documentation/urls/guide
使用此 API,您可以构建包含起点、目的地和航路点的 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);
关于android - Intent 使用 Google 导航获取具有多个航路点的行程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16717609/