使用python计算谷歌地图中2点之间的距离 [英] Calculate distance between 2 points in google maps using python

查看:738
本文介绍了使用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点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆