Python谷歌地图驾驶时间 [英] Python Google Maps Driving Time

查看:88
本文介绍了Python谷歌地图驾驶时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Python在两组坐标之间获得驾驶时间。 Google Maps API的唯一封装器我能够找到使用Google Maps API V2(不推荐使用)或者没有提供开车时间的功能。我在本地应用程序中使用它,并且不希望被绑定到使用JavaScript的Google Maps API V3中。

/ div>

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

  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 = zh-CN& sensor = false.format(str(orig_coord),str(dest_coord))
result = simplejson.load(urllib.urlopen( url))
driving_time = result ['rows'] [0] ['elements'] [0] ['duration'] ['value']


I need to get driving time between two sets of coordinates using Python. The only wrappers for the Google Maps API I have been able to find either use Google Maps API V2 (deprecated) or do not have the functionality to provide driving time. I'm using this in a local application and do not want to be bound to using JavaScript which is what the Google Maps API V3 is available in.

解决方案

Using URL requests to the Google Distance Matrix API and a json interpreter you can do this:

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谷歌地图驾驶时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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