Python 谷歌地图行车时间

标签 python google-maps google-maps-api-3

我需要使用 Python 获取两组坐标之间的行车时间。我能够找到的唯一的 Google Maps API 包装器要么使用 Google Maps API V2(已弃用),要么没有提供行车时间的功能。我在本地应用程序中使用它,不想受限于使用 JavaScript,这是 Google Maps API V3 中可用的。

最佳答案

使用对 Google Distance Matrix API 的 URL 请求和 json 解释器,您可以执行此操作:

import simplejson, urllib
orig_coord = orig_lat, orig_lng
dest_coord = dest_lat, dest_lng
url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode=driving&language=en-EN&sensor=false".format(str(orig_coord),str(dest_coord))
result= simplejson.load(urllib.urlopen(url))
driving_time = result['rows'][0]['elements'][0]['duration']['value']

关于Python 谷歌地图行车时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267807/

相关文章:

python - 定义一个新列并根据 Python 中的每个组给出值

php - 谷歌地图 API v2 - 动态加载(数万个)标记

google-maps-api-3 - 如何在 Google Maps Javascript API 3.x 中禁用 45 度选项

javascript - Google Maps API v3 不会在 map 加载后禁用滚轮

java - 热图未以 fragment 形式显示

javascript - 谷歌地图 - setIcon 代码使标记消失

python - 如何在 Django 1.5 中获取 FilePathField 的所有可用值?

python - pandas 中的数据争论

python - 为什么计算优先附着是昂贵的?

javascript - Google Maps JS API - 绘制具有静态中心的可调整大小的圆