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

1586010002-jmsa.png

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 ;-)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值