Python地理位置信息库geopy的使用:根据中心点坐标,方向,距离计算坐标
import geopy.distance
def get_distance_point(lat, lon, distance, direction):
"""
根据经纬度,距离,方向获得一个地点
:param lat: 纬度
:param lon: 经度
:param distance: 距离(千米)
:param direction: 方向(北:0,东:90,南:180,西:360)
:return:
"""
start = geopy.Point(lat, lon)
d = geopy.distance.VincentyDistance(kilometers=distance)
return d.destination(point=start, bearing=direction)
p = get_distance_point(34.490194, 117.281568, 0.5, 0)
print(p.latitude, p.longitude)
https://www.cnblogs.com/lloyd-zh/p/9805828.html
利用两点经纬度计算地理空间距离
from math import sin, asin, cos, radians, fabs, sqrt
EARTH_RADIUS = 6371.137 # 地球平均半径大约6371km
def hav(theta):
s = sin(theta / 2)
return s * s
def get_distance_hav(lat0, lng0, lat1, lng1):
# 用haversine公式计算球面两点间的距离
# 经纬度转换成弧度
lat0 = radians(lat0)
lat1 = radians(lat1)
lng0 = radians(lng0)
lng1 = radians(lng1)
dlng = fabs(lng0 - lng1)
dlat = fabs(lat0 - lat1)
h = hav(dlat) + cos(lat0) * cos(lat1) * hav(dlng)
distance = 2 * EARTH_RADIUS * asin(sqrt(h)) # km
return distance
if __name__ == "__main__":
result = get_distance_hav(39.995304, 116.308264, 40.003304, 116.326759)
print(result)
https://blog.csdn.net/chinawangfei/article/details/125458095