我想知道,如果可以在“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));
我读了其他问题,他们说使用这种语法:
"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
通过上述解决方案,“Google Navigation”不会自动启动,我们必须选择一个应用程序“Google Maps”,然后点击Itinerary(在屏幕顶部)启动“Google Navigation”。 如果可能的话,我想避免它。
答案 0 :(得分:16)
这是一种压制对话框并直接转到地图的方法。
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 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);
答案 1 :(得分:3)
检查这两种方法,它们都适合我。
方法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);
方法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);
答案 2 :(得分:0)
因为point1.longitude是Double,所以你应该使用这个
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)));
或者你可以使用它,但它是一样的。
point1.toString().replace("lat/lng: (", "").replace(")", "")
point1.toString()结果为&#34; lat / lng:(44.871709,-0.505704)&#34 ;,删除&#34; lat / lng :(&#34;和&#34; )&#34 ;. 然后你就可以得到你想要的结果。
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(")", "")));
或者你可以试试这个
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);
我希望这可以帮到你。
答案 3 :(得分:-1)
您必须只传递目的地位置。 Google地图应用会自动将您当前的位置用于导航。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + String.valueOf(destination latitude)
+ "," + String.valueOf(destination longitude)));
startActivity(intent);