如何在给定 gps 原点的情况下找到附近的点?

How to find nearby points given a gps origin?

如何根据 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)
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 那里学会了如何做到这一点。它不是完全相同的副本,但足以格式化此答案。您使用距离函数定义距离,然后沿随机方向离开一个点(函数的输入)。