谷歌地图:给定一个点,如何找到给定道路距离内的所有点? [英] Google Maps: Given a point, how to find all points at a given road distance?

查看:39
本文介绍了谷歌地图:给定一个点,如何找到给定道路距离内的所有点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,GPS 会选择车辆的位置.然后,如果车辆向任何方向行驶 1 公里,则应该在车辆可能到达的所有点上放置标记(请注意,在他的 1 公里范围内,道路可能会分叉多次).

In my app, the GPS picks the location of the vehicle. It is then supposed to put markers at all points where the vehicle could be if it drives for 1 KM in any direction (note that the roads may fork many times within his 1KM reach).

有人可以建议我怎么做吗?提前致谢.

Can someone suggest me how to do this? Thanks in advance.

推荐答案

这是使用 Google Maps API 解决的一个非常棘手的问题.以下是您可能需要考虑的一种方法:

This is a very tricky problem to solve with the Google Maps API. The following is one method that you may want to consider:

  1. 您可以轻松计算出围绕您的 GPS 点 1 公里的边界圆,也可以轻松计算任何角度的落在该圆圆周上的点.此距离将是乌鸦文件"而不是实际的道路距离,但您可能需要查看以下 Stack Overflow 帖子以了解具体实现:

  1. You can easily calculate a bounding circle of 1km around your GPS point, and it is also easy to calculate points that fall on the circumference of this circle, for any angle. This distance will be "as the crow files" and not the actual road distance, but you may want to check out the following Stack Overflow post for a concrete implementation of this:

如何计算距另一个点一定距离的点的纬度?

在半径为 1 公里的边界圆上以 20 度为间隔标记的屏幕截图:

Screenshot with markers at 20 degree intervals on a bounding circle with a 1km radius:

删除了无效的 ImageShack 链接 - 如何计算与另一个点相距一定距离的点的纬度?

  1. 还有一个技巧可以将这些点捕捉到最近的街道.您可以查看 Mike Williams 的 Snap point to street examples 以很好地实现这一点.

  1. There is also a trick to snap these points to the nearest street. You can check out Mike Williams' Snap point to street examples for a good implementation of this.

可以使用 Google Maps API 的路线服务来计算从 GPS 点到每个捕捉到的道路点的道路距离.请注意,这仅适用于支持谷歌地图方向的国家,但更重要的是,道路距离几乎总是大于 1 公里,因为我们的边界圆有 1 公里半径乌鸦飞".但是,如果您可以使用近似信息,这可能已经是一种可能的解决方案.

Calculating the road distance from your GPS point to each snapped road point could be done with the directions service of the Google Maps API. Note that this will only work in countries that support directions in Google Maps, but more importantly, the road distance will almost always be greater than 1km, because our bounding circle has a 1km radius "as the crow flies". However if you can work with approximate information, this may already be one possible solution.

你也可以考虑从上面的解决方案开始(1km的边界圆,计算圆周上的x个点,然后捕捉到最近的道路),然后计算每条路径的道路距离(从你的GPS点到每个捕捉点),然后您可以为每条路径递归重复此操作,每次使用较小的边界圆,直到您到达接近 1 公里的道路距离.您可以按误差幅度成比例地减少每次递归中的边界圆,以使您的算法更高效.

You can also consider starting with the above solution (1km bounding circle, calculate x points on the circumference, and snap them to the closest road), then calculate the road distance of each path (from your GPS point to each snapped point), and then you can repeat this this recursively for each path, each time using a smaller bounding circle, until you reach a road distance close to 1km. You can decrease the bounding circle in each recursion, in proportion to the error margin, to make your algorithm more efficient.

<小时>

更新:

我发现了一个非常简洁的实现,它似乎使用了与我上面描述的方法类似的方法:

I found a very neat implementation which appears to be using a similar method to the one I described above:

注意如何从顶部更改度数的间隔.如果间隔较大,您会很快得到结果,但很容易错过一些路线.

Note how you can change the interval of degrees from the top. With a wide interval you'll get fast results, but you could easily miss a few routes.

截图:

删除了无效的 ImageShack 链接 - 驾驶半径

这篇关于谷歌地图:给定一个点,如何找到给定道路距离内的所有点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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