如何利用python计算经纬度距离

复制代码
 1     def geodistance(self, lng1, lat1, lng2, lat2):
 2         # lng1,lat1,lng2,lat2 = (120.12802999999997,30.28708,115.86572000000001,28.7427)
 3         lng1, lat1, lng2, lat2 = map(radians, [float(lng1), float(lat1), float(lng2), float(lat2)])  # 经纬度转换成弧度
 4         dlon = lng2 - lng1
 5         dlat = lat2 - lat1
 6         a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
 7         distance = 2 * asin(sqrt(a)) * 6371 * 1000  # 地球平均半径,6371km
 8         # 单位:米
 9         distance = round(distance, 3)
10         return distance
复制代码

 

本文作者:自由风~

本文链接:https://www.cnblogs.com/lxpfree/p/15954621.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   自由风~  阅读(735)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.