使用python计算谷歌地图中2点之间的距离

编程入门 行业动态 更新时间:2024-10-27 05:33:28
本文介绍了使用python计算谷歌地图中2点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用gmail地理编码功能获取经度和纬度。现在我需要计算2点之间的距离。我发现Haversine公式,它运作良好,但后来在谷歌js api我找到了几何库中的方法computeDistanceBetween(lat,lng)。我的问题是有python的函数或库吗?

解决方案

from math import * def greatCircleDistance((lat1,lon1),(lat2,lon2)): def haversin(x): return sin(x / 2)** 2 $ return 2 * asin(sqrt( haversin(lat2-lat1)+ cos(lat1)* cos(lat2)* haversin(lon2-lon1)))

这将返回球体上各点之间的角距离。要获得长度(公里)的距离,请将结果与地球半径相乘。

但是,您也可以在公式集合中查找它, downvotes; - )

I get longitude and latitude using gmail geocode function. Now i need to calculate distance between 2 points. I found Haversine formula and it works well, but then in google js api i found method computeDistanceBetween(lat,lng) in the Geometry Library. My question is there a function or library for python?

解决方案

from math import * def greatCircleDistance((lat1, lon1), (lat2, lon2)): def haversin(x): return sin(x/2)**2 return 2 * asin(sqrt( haversin(lat2-lat1) + cos(lat1) * cos(lat2) * haversin(lon2-lon1)))

This returns the angular distance between the points on a sphere. To get a distance in length (kilometers), multiply the result with the Earth radius.

But you could have it looked up in a formula collection as well, hence the bunch of downvotes ;-)

更多推荐

使用python计算谷歌地图中2点之间的距离

本文发布于:2023-10-27 22:34:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   距离   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!