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

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

问题描述

在我的应用程序中,GPS采车辆的位置。它然后应该把标记在所有点处的车辆可能是,如果它在任何方向(注意,道路可能在他1KM到达叉多次)驱动为1 KM

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.

推荐答案

这是一个非常棘手的问题要解决与谷歌地图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. 您可以轻松地计算出1公里的边界一圈您的GPS点,而且也很容易计算出落在这个圆的周长,任何角度点。这个距离将是为乌鸦文件,而不是实际道路距离,但你可能想看看下面的堆栈溢出职位的具体实现这一点:

  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:

<一个href="http://stackoverflow.com/questions/2637023/how-to-calculate-the-latlng-of-a-point-a-certain-distance-away-from-another">How计算一个点的经纬度有一定距离的另一个?

截图与一公里半径的标志物上的包围一圈20度间隔:

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

删除死ImageShack环节 - 如何计算一个点的经纬度有一定距离的另一个

还有一个绝招,以捕捉这些点到最近的街道。您可以检查出迈克·威廉姆斯的捕捉点到街头范例一个很好的实现了这一点。

  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.

这是您的GPS点到每一个计算路途远近厉声道点可以与谷歌地图API的方向服务来完成。请注意,这仅适用于支持在谷歌地图的方向国家,但更重要的是,路途远近,几乎总是大于一公里,因为我们的边界圈有一公里半径的直线距离。但是,如果你可以用大致信息工作,这可能已经是一个可能的解决方案。

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.

您也可以考虑开始与上述溶液(1公里边界圈,计算圆周上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天全站免登陆