Python Google Maps Driving Time

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

    import googlemaps
    from datetime import datetime
    
    gmaps = googlemaps.Client(key='YOUR KEY')
    
    
    now = datetime.now()
    directions_result = gmaps.directions("18.997739, 72.841280",
                                         "18.880253, 72.945137",
                                         mode="driving",
                                         avoid="ferries",
                                         departure_time=now
                                        )
    
    print(directions_result[0]['legs'][0]['distance']['text'])
    print(directions_result[0]['legs'][0]['duration']['text'])
    

    This is been taken from here And alternatively you can change the parameters accordingly.

提交回复
热议问题