Skip to content

Instantly share code, notes, and snippets.

@philshem
Created April 7, 2014 09:45
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save philshem/10017416 to your computer and use it in GitHub Desktop.
Get latitude, longitude and other data from Google Maps geolocation API
import requests
import json
urlbase = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
urlend = 'Zurich,Switzerland'
r = requests.get(urlbase+urlend) # request to google maps api
r=r.json()
if r.get('results'):
for results in r.get('results'):
latlong = results.get('geometry','').get('location','')
latitude = latlong.get('lat','')
longitude = latlong.get('lng','')
break
print latitude, longitude
else:
print 'No results'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment