Google Maps JavaScript API v3 directions capabilities

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

I use Google Maps js API v3. I can show directions with waypoints based on this. What I want is getting the points of the direction. Lets say the direction line goes from Budapest to Warsaw. I want to get all latitude and longitude on that line. But I don't find any build in function or workaround for this. I don't copy code here as the tutorial works for me, I can start from that. (Of course it isn't a good idea to make lot of waypoints.)

I've seen this question. It isn't solution for my problem, as its not for API3

Thanks in advance.

UPDATE: Based on Matty F's answer I found out I searched for the result object's routs array's overview_path field. Thank you.

回答1:

When calling the DirectionsService.route method, pass a callback as the second parameter. The first parameter in the callback will be a DirectionsResult object. Get all the points of the directions by looping through the children of this object:

DirectionsService.route(request, function(result, status) {     var pointsArray = [];      for (var route in result.routes) {         for (var leg in route.legs) {             for (var step in leg.steps) {                 for (var latlng in step.path) {                     pointsArray.push(latlng)                 }             }         {     } }); 

In the end, pointsArray will hold all the LatLng points between the start and destination points.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!