[英]How to find nearby points given a gps origin?
How does one find a nearby point given a gps coordinate? 给定gps坐标时如何找到附近的点? The new point can be randomly chosen, but must be within 100 meters of the origin.
新点可以随机选择,但必须在原点100米范围内。 Collisions are fine as well.
碰撞也很好。
ie, 即
origin = (latitude, longitude)
# prints one nearby point in (lat, lon)
print "%s, %s" % get_nearby_point(origin)
# prints another nearby point in (lat, lon)
print "%s, %s" % get_nearby_point(origin)
import geopy.distance
from random import random
def get_nearby_point(origin):
dist = geopy.distance.VincentyDistance(kilometers = .1)
pt = dist.destination(point=geopy.Point(origin), bearing=random()*360)
return pt[0],pt[1]
origin = (34.2234, 14.252) # I picked some mostly random numbers
# prints one nearby point in (lat, lon)
print "%s, %s" % get_nearby_point(origin)
# prints another nearby point in (lat, lon)
print "%s, %s" % get_nearby_point(origin)
Results: 结果:
$ python nearby.py
34.2225717618, 14.2524285475
34.2225807815, 14.2524529774
I learned how to do this from here . 我从这里学会了如何做到这一点 。 It's not an exact duplicate, but it's enough to format this answer.
这不是一个完全重复,但它足以格式化这个答案。 You define a distance using the distance function then you move off a point, the input to the function, in a random direction.
您可以使用距离函数定义距离,然后以随机方向移动一个点(函数的输入)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.