Created
December 7, 2015 22:52
-
-
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
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
# 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