传入两点经纬度,求出距离
def calcDistance(Lng_A, Lat_A, Lng_B, Lat_B):
"""
根据两个点的经纬度求两点之间的距离,注意需要乘以1000,因为返回的单位为千米
:param Lng_A:
:param Lat_A:
:param Lng_B:
:param Lat_B:
:return:
"""
ra = 6378.140
rb = 6356.755
flatten = (ra - rb) / ra
rad_lat_A = radians(Lat_A)
rad_lng_A = radians(Lng_A)
rad_lat_B = radians(Lat_B)
rad_lng_B = radians(Lng_B)
pA = atan(rb / ra * tan(rad_lat_A))
pB = atan(rb / ra * tan(rad_lat_B))
xx = acos(sin(pA) * sin(pB) + cos(pA) * cos(pB) * cos(rad_lng_A - rad_lng_B))
c1 = (sin(xx) - xx) * (sin(pA) + sin(pB)) ** 2 / cos(xx / 2) ** 2
# 经测试当传入这两个点的经纬度一样时会返回 *
if sin(xx/2)==0:
return '*'
c2 = (sin(xx) + xx) * (sin(pA) - sin(pB)) ** 2 / sin(xx / 2) ** 2
dr = flatten / 8 * (c1 - c2)
distance = ra * (xx + dr)
return distance
```