Last active
August 29, 2015 13:57
-
-
Save raianul/9426669 to your computer and use it in GitHub Desktop.
Get Google Map Direction by location and destination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
GOOGLE_API = { | |
'distance': 'http://maps.googleapis.com/maps/api/directions/json' | |
} | |
def get(key, options): | |
if key not in GOOGLE_API: | |
return False | |
r = requests.get(GOOGLE_API[key], params=options) | |
return r.json() | |
# Set location parameter is more specifically | |
# origin: Uttara, Dhaka, Bangladesh | |
# destination: Mirpur, Dhaka, Bangladesh | |
# set alternatives as true to get alternate path | |
params = { | |
'mode': 'driving', | |
'origin': 'Uttara, Dhaka, Bangladesh', | |
'destination': 'Mirpur, Dhaka, Bangladesh', | |
'sensor': 'false', | |
'alternatives': 'false' | |
} | |
results = get('distance', params) | |
if results['status'] == 'OK': | |
print "Distance: " + results['routes'][0]['legs'][0]['distance']['text'] | |
print "Duration: " + results['routes'][0]['legs'][0]['duration']['text'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment