# 经纬度、高程计算距离
import math
EARTH_REDIUS = 6378.137
# Lat1 Lung1 表示A点纬、经度,Lat2 Lung2 表示B点纬、经度
def rad(d):
return d * math.pi / 180.0
def getDistance(lat1, lng1, h1, lat2, lng2, h2):
radLat1 = rad(lat1)
radLat2 = rad(lat2)
a = radLat1 - radLat2
b = rad(lng1) - rad(lng2)
s = 2 * math.asin(math.sqrt(math.pow(math.sin(a/2), 2) + math.cos(radLat1) * math.cos(radLat2) * math.pow(math.sin(b/2), 2)))
s = s * EARTH_REDIUS
s = math.sqrt(s*s+(h1-h2)*(h1-h2))
return s