Python Google Maps Driving Time

前端 未结 4 1917
感动是毒
感动是毒 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:28

    Updated the Accepted Answer to include the API Key and use a string for the addresses.

    import simplejson, urllib
    KEY = "xxxxxxxxxxxxxx"
    
    orig = "Street Address 1"
    dest = "Street Address 2"
    url = "https://maps.googleapis.com/maps/api/distancematrix/json?key={0}&origins={1}&destinations={2}&mode=driving&language=en-EN&sensor=false".format(KEY,str(orig),str(dest))
    result= simplejson.load(urllib.urlopen(url))
    #print(result)
    driving_time = result['rows'][0]['elements'][0]['duration']['text']
    print(driving_time)
    
    

提交回复
热议问题