2 回答
TA贡献1795条经验 获得超7个赞
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
radius = 6371 # km
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
* math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = radius * c
return d
pos = [
(u'node0:', 21.78400936610002, 38.2874355527483),
(u'node1:', 21.78453228393861, 38.28690995466475),
(u'node2:', 21.7848823502596, 38.2869152766261),
(u'node3:', 21.78459887820567, 38.28740826552452)]
node0 = [p for p in pos if p[0] == 'node0:'][0]
dist=(distance(node0[1:3], p[1:3]) for p in pos if p[0] != 'node0:')
for d in dist: print(d)
添加回答
举报