utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mobileinsight-mobile 作者: mobile-insight 项目源码 文件源码
def haversine(lon1, lat1, lon2, lat2):
    """
    Calculate the great circle distance between two points
    on the earth (specified in decimal degrees)

    Taken from: http://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points
    """
    # 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))
    km = 6367 * c
    return km
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号