Skip to content

Instantly share code, notes, and snippets.

@ImSingee
Created June 13, 2018 16:08
Show Gist options
  • Save ImSingee/e6f561410ecb70071e7935fd4cc6fe32 to your computer and use it in GitHub Desktop.
Save ImSingee/e6f561410ecb70071e7935fd4cc6fe32 to your computer and use it in GitHub Desktop.
计算经纬度距离差
def get_distance(latitude_start, latitude_end, longitude_start, longitude_end):
"""
计算经纬度距离差
:param latitude_start: 纬度1
:param latitude_end: 纬度2
:param longitude_start: 经度1
:param longitude_end: 经度2
:return:
"""
import math
# 角度转弧度
rad_latitude_start = math.radians(latitude_start)
rad_latitude_end = math.radians(latitude_end)
rad_longitude_start = math.radians(longitude_start)
rad_longitude_end = math.radians(longitude_end)
# 求弧度差
d_latitude = rad_latitude_start - rad_latitude_end
d_longitude = rad_longitude_start - rad_longitude_end
# 求距离
distance = 2 * 6378.137 * math.asin(math.sqrt(
math.pow(math.sin(d_latitude / 2), 2) +
math.cos(rad_latitude_start) * math.cos(rad_latitude_end) * math.pow(math.sin(d_longitude / 2), 2)
))
return distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment