Created
November 2, 2011 04:30
-
-
Save key/1332860 to your computer and use it in GitHub Desktop.
python geocoding (using Google Maps API service)
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
def geocoding(address): | |
from httplib2 import Http | |
import simplejson | |
url_prefix = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' | |
(header, response) = Http().request(url_prefix + address) | |
decoder = simplejson.JSONDecoder() | |
dict_ = decoder.decode(response) | |
try: | |
location = dict_['results'][0]['geometry']['location'] | |
except IndexError: | |
return None | |
lat = location['lat'] | |
lng = location['lng'] | |
return (lat, lng) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment