# 【已解决】Python中如何计算两个经纬度的点之间的距离

Python 5745浏览

【已解决】如何判断某个经纬度位置在某个位置点的某个直径范围内

【地理】两点间方向和距离的判断_调研_新浪博客

mysql 下 计算 两点 经纬度 之间的距离 计算结果排序 – 静下心来写代码 – 博客频道 – CSDN.NET

python latitude longitude distance

Calculate distance between latitude longitude pairs with Python · GitHub

 #!/usr/bin/env python# Haversine formula example in Python# Author: Wayne Dyckimport mathdef distance(origin, destination):    lat1, lon1 = origin    lat2, lon2 = destination    radius = 6371 # km    dlat = math.radians(lat2-lat1)    dlon = math.radians(lon2-lon1)    a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \        * math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))    d = radius * c    return d

Haversine Formula in Python (Bearing and Distance between two GPS points) – Stack Overflow

 from math import radians, cos, sin, asin, sqrtdef haversine(lon1, lat1, lon2, lat2):    “””    Calculate the great circle distance between two points     on the earth (specified in decimal degrees)    “””    # convert decimal degrees to radians     lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])    # haversine formula     dlon = lon2 – lon1     dlat = lat2 – lat1     a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2    c = 2 * asin(sqrt(a))     r = 6371 # Radius of earth in kilometers. Use 3956 for miles    return c * r

python – How can I quickly estimate the distance between two (latitude, longitude) points? – Stack Overflow

geocoding – Getting distance between two points based on latitude/longitude [python] – Stack Overflow

 pip install gpxpy –userimport gpxpy.geo# Point onelat1 = 52.2296756lon1 = 21.0122287# Point twolat2 = 52.406374lon2 = 16.9251681# What you were looking fordist = gpxpy.geo.haversine_distance(lat1, lon1, lat2, lon2)print(dist)

GitHub – tkrajina/gpxpy: gpx-py is a python GPX parser. GPX (GPS eXchange Format) is a XML based file format for GPS track logs.

geopy 1.11.0 : Python Package Index

【整理】地球半径到底是多少

【总结】

 from math import radians, cos, sin, asin, sqrt### calculate distance of two point# http://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points#def haversine(lon1, lat1, lon2, lat2):def calcDistance(lon1, lat1, lon2, lat2):    “””    Calculate the great circle distance between two points    on the earth (specified in decimal degrees)    “””    # convert decimal degrees to radians    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])    # haversine formula    dlon = lon2 – lon1    dlat = lat2 – lat1    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2    c = 2 * asin(sqrt(a))    EARTH_RADIUS = 6371 # Radius of earth in kilometers. Use 3956 for miles    return c * EARTH_RADIUS

 calculatedDistance = calcDistance(  curUser.location.longitude,                                                curUser.location.latitude,                                                eachUserLocation.longitude,                                                eachUserLocation.latitude)            gLog.debug(“curUser.location=%s, eachUserLocation=%s -> calculatedDistance=%s”,                       curUser.location, eachUserLocation, calculatedDistance)

 curUser.location=, eachUserLocation= -> calculatedDistance=0.463593304637
89 queries in 0.201 seconds, using 22.19MB memory