使用谷歌地图为大量节点找到最短路径 [英] finding shortest paths using google maps for a large number of nodes

查看:248
本文介绍了使用谷歌地图为大量节点找到最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为客户端进行一些网络分析。提供的道路网络GIS层质量差;因此,我必须使用谷歌地图为我提供200点之间的最短路径,以产生每个点之间的时间和距离矩阵。

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.

有没有办法可以输入该层作为一组KML点来获得这些点之间的距离和时间的输出?

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 ?

如果可以通过api这样做,你对如何编写这样的脚本有任何提示或建议吗?

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

编辑
理想的最终结果将是以下格式的CSV文件:

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


推荐答案

我不会为您编写整个脚本,但这可以使用maps API完成。打开地图沙箱并添加到onGDirectionsLoad功能:

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);

您可以找到文档此处 - getDuration()也可用。然后你需要做的就是在一个完成后发出一个新的请求,获得每对开始和结束点的指示。

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.

但是,请注意,如果你正在计划在获得200 * 200路径时,谷歌可能会决定在某些时候限制你。使用此方法需要您自担风险,并且请求之间会有延迟。

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.

另请注意Google的内置KML支持似乎不支持为您提供点列表 - 这是有道理的,因为客户端可能只有那些目前在屏幕上。如果要使用KML作为输入格式,则可能需要编写自己的KML加载程序。或者使用更简单的格式,例如此示例

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.

这篇关于使用谷歌地图为大量节点找到最短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆