通过将航点至Google地图Android的创建电路路径
我的功能,我送waypoints
到Gmaps
应用程序通过Intent
工作,使得在使用可以导航到目的地由自定义waypoints
我送通过将航点至Google地图Android的创建电路路径
我时,我的情节此路线在我的嵌入式Google Maps
中,我可以看到Circuit route
,但是当我在Gmaps
应用中看到相同的路由时,Circuit
已损坏。
我的代码:
String srcAdd = "saddr="+latLngArrayList.get(0).latitude+","+latLngArrayList.get(0).longitude;
String desAdd = "&daddr="+latLngArrayList.get(latLngArrayList.size() - 1).latitude+","+latLngArrayList.get(latLngArrayList.size() - 1).longitude;
String wayPoints = "";
for (int j = 1; j < latLngArrayList.size() - 1; ++j) {
wayPoints =wayPoints+"+to:"+latLngArrayList.get(j).latitude+","+latLngArrayList.get(j).longitude;
}
String link="https://maps.google.com/maps?"+srcAdd+desAdd+wayPoints;
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
我建议在看看Google Maps URLs API这是launc hed。该API提供了一个通用的跨平台链接,您可以在应用程序中使用这些链接来启动Google地图。其中一种支持的模式是方向模式。你可以在这里读到它:
https://developers.google.com/maps/documentation/urls/guide#directions-action
当您使用方向API和发布航点的样品坐标,我能够来测试Web服务和谷歌地图的URL的结果。
的Web服务结果在路线计算工具进行了测试:
,我们通过地图API中得到的路线如下
的谷歌地图的URL链接,这些航点是以下
你开始使用谷歌地图的URL路径在这个截图
所示正如你可以看到两条路线都是一样的,所以地图API和谷歌地图的URL正常工作。我相信你应该改变你的代码的意图来使用谷歌地图网址:
String srcAdd = "&origin=" + latLngArrayList.get(0).latitude + "," + latLngArrayList.get(0).longitude;
String desAdd = "&destination=" + latLngArrayList.get(latLngArrayList.size() - 1).latitude + "," + latLngArrayList.get(latLngArrayList.size() - 1).longitude;
String wayPoints = "";
for (int j = 1; j < latLngArrayList.size() - 1; j++) {
wayPoints = wayPoints + (wayPoints.equals("") ? "" : "%7C") + latLngArrayList.get(j).latitude + "," + latLngArrayList.get(j).longitude;
}
wayPoints = "&waypoints=" + wayPoints;
String link="https://www.google.com/maps/dir/?api=1&travelmode=driving"+srcAdd+desAdd+wayPoints;
final Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
此外,您可以以直接打开的turn-by-turn导航使用dir_action=navigate
参数。
我希望这有助于!
谢谢主席先生的回答。链接的路线(形成的电路)与我所期望的不同。我还是不明白这发生了什么?请在邮件中查看我的线路图。 –
这确实不同,但Directions API中的建议路线可能每天都有所不同。 Google会考虑交通状况并返回最快的路线,而不是最短路线,因此您可以看到一段时间内不同的路线。这是预料之中的。如果您需要完全相同的路线,请添加更多路标以更好地控制输出。你有方向计算器玩路线和航点。 – xomena
先生,我尝试了一些创建额外路点以创建所需电路的工作。主席先生,你的回答帮了我。谢谢你:) –
如何在应用程序活动中构建路线?你是否执行Directions API请求来获取多段线?您能否提供原始地点,目的地和航点的确切数值以在Google地图应用中重现问题? – xomena
是的,我使用方向API。 –
原点,目的地和航点的值如何?我需要他们来重现这个问题,否则我无法帮助。 – xomena