最近遇到一个需求,使用pyhon 获取雷达设备中的数据并解析,将返回数据中包含方位角、速度、距离等,需要使用获得的数据来计算目标经纬度!
import math
lon = 23.1090329023218
lat = 113.64838778972626
l_azimuth = 23
l_distance = 0.5 # km
# 已知起点经纬度,使用距离与方位角求终点经纬度
def get_destination(lat1: float, lon1: float, azimuth: float, distance: float) -> list:
"""
已知起点经纬度,使用距离与方位角求终点经纬度
:param lat1: 已知纬度
:param lon1: 已知经度
:param azimuth: 已知方位角 °
:param distance: 已知距离 km
:return: 终点经纬度
"""
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
azimuth = math.radians(azimuth)
distance = distance / 6378.1
lat2 = math.asin(math.sin(lat1) * math.cos(distance) + math.cos(lat1) * math.sin(distance) * math.cos(azimuth))
lon2 = lon1 + math.atan2(math.sin(azimuth) * math.sin(distance) * math.cos(lat1),
math.cos(distance) - math.sin(lat1) * math.sin(lat2))
lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)
return [lat2, lon2]
print(get_destination(lon, lat, 2.1, l_distance))
# 生成经纬度坐标并输出JS语句应用到地图上
for i in range(0, 8):
z = get_destination(lon, lat, (i + 1) * 45, l_distance)
print('L.marker([%s, %s]).addTo(map).bindPopup("角度:%d°
距离:%f米");' % (z[0], z[1], (i + 1) * 45, l_distance * 1000))
Nginx使用宝典 (tboai.com)