经纬度坐标间的距离

2018-01-16  本文已影响0人  领悟悟悟
 def get_distance2(lon_a, lat_a, lon_b, lat_b):
   if abs(lon_a - lon_b) < 0.000001 and abs(lat_a - lat_b) < 0.000001:
      return 0
    re = 6378140  # 赤道半径 (m)
    rp = 6356755  # 极半径 (m)
    oblateness = (re - rp) / re  # 地球扁率
    rad_lat_a = radians(lat_a)
    rad_lon_a = radians(lon_a)
    rad_lat_b = radians(lat_b)
    rad_lon_b = radians(lon_b)
    atan_a = atan(rp / re * tan(rad_lat_a))
    atan_b = atan(rp / re * tan(rad_lat_b))
    tmp = acos(sin(atan_a) * sin(atan_b) + cos(atan_a) * cos(atan_b) * cos(rad_lon_a - rad_lon_b))
    if tmp == 0:
      return 0
    c1 = (sin(tmp) - tmp) * (sin(atan_a) + sin(atan_b)) ** 2 / cos(tmp / 2) ** 2
    c2 = (sin(tmp) + tmp) * (sin(atan_a) - sin(atan_b)) ** 2 / sin(tmp / 2) ** 2
      dr = oblateness / 8 * (c1 - c2)
    distance = re * (tmp + dr)
    return distance # 单位m
参考:
【Python学习】指定两点地理位置经纬度的距离计算
经纬度计算小工具
Python根据经纬度求两点间距离
给你两个经纬度,计算他们之间的距离
上一篇下一篇

猜你喜欢

热点阅读