今天就跟大家聊聊有关Python实现经纬度坐标转换为距离及角度,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1 经纬度转换距离代码
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Seven' import math # 计算距离 def getDistance(latA, lonA, latB, lonB): ra = 6378140 # 赤道半径 rb = 6356755 # 极半径 flatten = (ra - rb) / ra # Partial rate of the earth # change angle to radians radLatA = math.radians(latA) radLonA = math.radians(lonA) radLatB = math.radians(latB) radLonB = math.radians(lonB) pA = math.atan(rb / ra * math.tan(radLatA)) pB = math.atan(rb / ra * math.tan(radLatB)) x = math.acos(math.sin(pA) * math.sin(pB) + math.cos(pA) * math.cos(pB) * math.cos(radLonA - radLonB)) c1 = (math.sin(x) - x) * (math.sin(pA) + math.sin(pB)) ** 2 / math.cos(x / 2) ** 2 c2 = (math.sin(x) + x) * (math.sin(pA) - math.sin(pB)) ** 2 / math.sin(x / 2) ** 2 dr = flatten / 8 * (c1 - c2) distance = ra * (x + dr) distance = round(distance / 1000, 4) return f'{distance}km'
标题名称:Python实现经纬度坐标转换为距离及角度-创新互联
网站地址:https://www.cdcxhl.com/article33/coipss.html
成都网站建设公司_创新互联,为您提供网站设计公司、品牌网站制作、网站制作、定制网站、网站维护、响应式网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联