Created
April 7, 2014 09:45
-
-
Save philshem/10017416 to your computer and use it in GitHub Desktop.
Get latitude, longitude and other data from Google Maps geolocation API
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 | |
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