Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Last active December 23, 2015 17:49
Show Gist options
  • Save Luzifer/6671737 to your computer and use it in GitHub Desktop.
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
#!/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