1.经纬度与距离角度的换算关系:

a)在纬度相等的情况下:

经度每隔0.00001度,距离相差约1米;

每隔0.0001度,距离相差约10米;

每隔0.001度,距离相差约100米;

每隔0.01度,距离相差约1000米;

每隔0.1度,距离相差约10000米。

b)在经度相等的情况下:

纬度每隔0.00001度,距离相差约1.1米;

每隔0.0001度,距离相差约11米;

每隔0.001度,距离相差约111米;

每隔0.01度,距离相差约1113米;

每隔0.1度,距离相差约11132米。

c)换算
地球赤道上环绕地球一周走一圈共 40075.04公里
而一圈分成360°
而每1°(度)有60’
每一度一秒在赤道上的长度计算如下:
40075.04km/360°=111.31955km
111.31955km/60’=1.8553258km=1855.3m
而每一分又有60秒
每一秒就代表 1855.3m/60=30.92m
任意两点距离计算公式为
d=111.12cos{1/[sinΦAsinΦB十 cosΦAcosΦBcos

2 Python代码实现

1.经纬度转换为距离

import math
 
 
# 计算距离
def getDistance(latA, lonA, latB, lonB):
    ra = 6378140  # 赤道半径
    rb = 6356755  # 极半径
    flatten = (ra - rb) / ra  # Partial rate of the earth
    # change angle to radians
    radLatA = math.radians(latA)
    radLonA = math.radians(lonA)
    radLatB = math.radians(latB)
    radLonB = math.radians(lonB)
 
    pA = math.atan(rb / ra * math.tan(radLatA))
    pB = math.atan(rb / ra * math.tan(radLatB))
    x = math.acos(math.sin(pA) * math.sin(pB) + math.cos(pA) * math.cos(pB) * math.cos(radLonA - radLonB))
    c1 = (math.sin(x) - x) * (math.sin(pA) + math.sin(pB)) ** 2 / math.cos(x / 2) ** 2
    c2 = (math.sin(x) + x) * (math.sin(pA) - math.sin(pB)) ** 2 / math.sin(x / 2) ** 2
    dr = flatten / 8 * (c1 - c2)
    distance = ra * (x + dr)
    distance = round(distance / 1000, 4)
    return f'{distance}km'

2.经纬度转换角度代码

import math
 
# 计算角度
def getDegree(latA, lonA, latB, lonB):
    radLatA = math.radians(latA)
    radLonA = math.radians(lonA)
    radLatB = math.radians(latB)
    radLonB = math.radians(lonB)
    dLon = radLonB - radLonA
    y = math.sin(dLon) * math.cos(radLatB)
    x = math.cos(radLatA) * math.sin(radLatB) - math.sin(radLatA) * math.cos(radLatB) * math.cos(dLon)
    brng = math.degrees(math.atan2(y, x))
    brng = round((brng + 360) % 360, 4)
    brng = int(brng)
    if (brng == 0.0) or ((brng == 360.0)):
        return '正北方向'
    elif brng == 90.0:
        return '正东方向'
    elif brng == 180.0:
        return '正南方向'
    elif brng == 270.0:
        return '正西方向'
    elif 0 < brng < 90:
        return f'北偏东{brng}'
    elif 90 < brng < 180:
        return f'东偏南{brng - 90}'
    elif 180 < brng < 270:
        return f'西偏南{270 - brng}'
    elif 270 < brng < 360:
        return f'北偏西{brng - 270}'
    else:
        pass

验证:
选取深圳野生动物园(22.599578, 113.973129)为起点,深圳坪山站(22.6986848, 114.3311032)为终点,结合百度地图、谷歌地图等进行效果验证。
在这里插入图片描述
即,百度测距为38.3km

Google地图手动测距为39.31km
在这里插入图片描述
在这里插入图片描述
参考:
https://blog.csdn.net/qq_23392639/article/details/89446703
http://blog.itblood.com/952.html
http://wenda.tianya.cn/question/151ddd808627a78b

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐