finding shortest paths using google maps for a large number of nodes

依然范特西╮ 提交于 2020-01-01 22:13:47

问题


I'm trying to do some network analysis for a client. The provided road-network GIS layer is of bad quality; therefore, I have to resort to Google maps to provide me shortest path between 200 points, to produce time and distance matrices between each point.

is there a way i can input the layer as a set of KML points to obtain outputs of the distance and time between these points ?

if this is doable via the api, do you have any hints or suggestions on how to write such a script?

EDIT the ideal final result would be a CSV file of the following form:

node_1, node_2, distance, travel_time
node_n, node_m, distance, travel_time

回答1:


I won't write the whole script for you, but this can be done with the maps API. Open up the maps sandbox and add to the onGDirectionsLoad function:

alert(gdir.getDistance().meters);

You can find the documentation here - a getDuration() is also available. Then all you need to do is issue a new request once one finished, getting directions for each pair of start and end point.

However, note that if you're planning on getting 200*200 paths, google may decide to rate limit you at some point. Use this method at your own risk, and with a delay between requests.

Note also that google's builtin KML support doesn't seem to support giving you the list of points - this makes sense, since the client may only have those that are currently onscreen. You might need to write your own KML loader if you want to use KML as the input format. Or use a simpler format, as in this example.



来源:https://stackoverflow.com/questions/1218048/finding-shortest-paths-using-google-maps-for-a-large-number-of-nodes

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