Python Google Maps Driving Time

前端 未结 4 1916
感动是毒
感动是毒 2021-01-30 05:33

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 (deprec

4条回答
  •  一整个雨季
    2021-01-30 06:13

    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']
    

提交回复
热议问题