Skip to content

Instantly share code, notes, and snippets.

@alexchantavy
Created December 7, 2015 22:52
Show Gist options
  • Save alexchantavy/0b2b3c5d672ef6205337 to your computer and use it in GitHub Desktop.
Save alexchantavy/0b2b3c5d672ef6205337 to your computer and use it in GitHub Desktop.
uses google's map geocoding api to find neighborhood names of a list of addresses
# uses google's map geocoding api to find neighborhood names of a list of addresses
import json, requests, urllib
addrs = [] # put your own addresses here
result = {}
for addr in addrs:
params = {'address': addr, 'key': api_key}
encoded_req = 'https://maps.googleapis.com/maps/api/geocode/json?%s' % urllib.urlencode(params)
returnedobj = requests.get(encoded_req)
data = json.loads(returnedobj.content)
neighborhood = data[u'results'][0][u'address_components'][2][u'long_name']
result[addr] = neighborhood
# now just print out the result dict in the way that you want
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment