Last active
December 23, 2015 17:49
-
-
Save Luzifer/6671737 to your computer and use it in GitHub Desktop.
Need a quick overview how long you will need by car from geolocation xx.xxxx,yy.yyyy to xx.xxxx,yy.yyyy? Just ask: python traveltime.py xx.xxxx,yy.yyyy xx.xxxx,yy.yyyy
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
#!/usr/bin/env python | |
import urllib, json, sys | |
if len(sys.argv) < 3: | |
print 'Usage: %s <lat,lon> <lat,lon>' % sys.argv[0] | |
sys.exit(2) | |
url = 'http://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&sensor=false' % (sys.argv[1], sys.argv[2]) | |
result = json.loads(urllib.urlopen(url).read()) | |
duration = result['routes'][0]['legs'][0]['duration']['text'] | |
distance = result['routes'][0]['legs'][0]['distance']['text'] | |
print '%s for %s' % (duration, distance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment