Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 807 Bytes

199.md

File metadata and controls

29 lines (25 loc) · 807 Bytes
@author jackzhenguo
@desc 求两点球面距离
@tag
@version 
@date 2020/04/06
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
[上一个例子](198.md) [下一个例子](200.md)