2017-10-21 29 views
0

我的功能,我送waypointsGmaps应用程序通过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); 

电路航线 enter image description here

没有电路路径 enter image description here

+0

如何在应用程序活动中构建路线?你是否执行Directions API请求来获取多段线?您能否提供原始地点,目的地和航点的确切数值以在Google地图应用中重现问题? – xomena

+0

是的,我使用方向API。 –

+0

原点,目的地和航点的值如何?我需要他们来重现这个问题,否则我无法帮助。 – xomena

回答

1

我建议在看看Google Maps URLs API这是launc hed。该API提供了一个通用的跨平台链接,您可以在应用程序中使用这些链接来启动Google地图。其中一种支持的模式是方向模式。你可以在这里读到它:

https://developers.google.com/maps/documentation/urls/guide#directions-action

当您使用方向API和发布航点的样品坐标,我能够来测试Web服务和谷歌地图的URL的结果。

的Web服务结果在路线计算工具进行了测试:

https://directionsdebug.firebaseapp.com/?origin=19.07598304748535%2C72.87765502929688&destination=19.07598304748535%2C72.87765502929688&waypoints=18.7284%2C73.4815%7C18.6876%2C73.4827%7C18.5839587%2C73.5125092%7C18.5369444%2C73.4861111%7C18.480567%2C73.491658

,我们通过地图API中得到的路线如下

enter image description here

的谷歌地图的URL链接,这些航点是以下

https://www.google.com/maps/dir/?api=1&origin=19.07598304748535,72.87765502929688&destination=19.07598304748535,72.87765502929688&waypoints=18.7284,73.4815%7C18.6876,73.4827%7C18.5839587,73.5125092%7C18.5369444,73.4861111%7C18.480567,73.491658&travelmode=driving

你开始使用谷歌地图的URL路径在这个截图

enter image description here

所示正如你可以看到两条路线都是一样的,所以地图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参数。

我希望这有助于!

+0

谢谢主席先生的回答。链接的路线(形成的电路)与我所期望的不同。我还是不明白这发生了什么?请在邮件中查看我的线路图。 –

+0

这确实不同,但Directions API中的建议路线可能每天都有所不同。 Google会考虑交通状况并返回最快的路线,而不是最短路线,因此您可以看到一段时间内不同的路线。这是预料之中的。如果您需要完全相同的路线,请添加更多路标以更好地控制输出。你有方向计算器玩路线和航点。 – xomena

+0

先生,我尝试了一些创建额外路点以创建所需电路的工作。主席先生,你的回答帮了我。谢谢你:) –

相关问题