Python实现经纬度坐标转换为距离及角度-创新互联
                                            今天就跟大家聊聊有关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实现经纬度坐标转换为距离及角度-创新互联
URL标题:http://www.cqwzjz.cn/article/coipss.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 