如何找到gps原点的附近点?

时间:2016-07-28 21:17:25

标签: python python-2.7 gps coordinates geopy

如何根据gps坐标找到附近的点?新点可以随机选择,但必须在原点100米范围内。碰撞也很好。

即,

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)

1 个答案:

答案 0 :(得分:3)

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)

结果:

$ python nearby.py 
34.2225717618, 14.2524285475
34.2225807815, 14.2524529774

我从here学会了如何做到这一点。这不是一个完全重复,但它足以格式化这个答案。您可以使用距离函数定义距离,然后沿着随机方向移动一个点(函数的输入)。