EARTH_RADIUS = 6378.137 import math # 角度弧度计算公式 def get_radian(degree): return degree * 3.1415926 / 180.0 # 根据经纬度计算两点之间的距离,得到的单位是 千米 def get_distance(lat1,lng1,lat2,lng2): radLat1 = get_radian(lat1) radLat2 = get_radian(lat2) a = radLat1 - radLat2 # 两点纬度差 b = get_radian(lng1) - get_radian(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_RADIUS return s