经纬度坐标距离

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import math

def coord_dist(lat1, lnt1, lat2, lnt2):
sin = math.sin
cos = math.cos
acos = math.acos
deg2rad = math.radians

R = 63713930
lat1 = deg2rad(lat1)
lnt1 = deg2rad(lnt1)
lat2 = deg2rad(lat2)
lnt2 = deg2rad(lnt2)
l = R * acos(cos(lnt1)*cos(lnt2)*cos(lat1-lat2)+sin(lnt1)*sin(lnt2))
return l