zoukankan      html  css  js  c++  java
  • python两个经纬度间的距离计算

    # coding: utf-8
    # author: lovecjy
    # created_time: 2021/6/4
    
    # https://blog.csdn.net/sinat_29675423/article/details/87879587
    # python计算两个经纬度之间的距离
    import math
    from math import pi
    
    # lat lon - > distance
    # 计算经纬度之间的距离,单位为千米
    
    EARTH_REDIUS = 6378.137
    
    
    def rad(d):
    	return d * pi / 180.0
    
    
    def getDistance(lat1, lng1, lat2, lng2):
    	radLat1 = rad(lat1)
    	radLat2 = rad(lat2)
    	a = radLat1 - radLat2
    	b = rad(lng1) - rad(lng2)
    	s = 2 * math.asin(
    		math.sqrt(math.pow(math.sin(a / 2), 2) + math.cos(radLat1) * math.cos(radLat2) * math.pow(math.sin(b / 2), 2)))
    	s = s * EARTH_REDIUS
    	return s
    
    
    if __name__ == '__main__':
    	ret = getDistance(30.28708, 120.12802999999997, 28.7427, 115.86572000000001)
    	print(ret)
    
    
    # 拓展:https://www.cnblogs.com/andylhc/p/9481636.html
    # 根据经纬度坐标计算距离-python
    

    以上。

  • 相关阅读:
    5059 一起去打CS
    2439 降雨量
    vijos P1037搭建双塔
    4979 数塔
    2596 售货员的难题
    P2342 叠积木
    1540 银河英雄传说
    1051 接龙游戏
    hdu1251
    洛谷P1717 钓鱼
  • 原文地址:https://www.cnblogs.com/lovebkj/p/14848910.html
Copyright © 2011-2022 走看看