Created
July 6, 2017 15:29
-
-
Save jakeemerson/78b85748d5ee190da95150b8888454a8 to your computer and use it in GitHub Desktop.
Using the google geocode 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 pandas as pd | |
import re | |
import urllib2 | |
import pprint | |
import json | |
def geocode(place): | |
add = urllib2.quote(place) | |
geocode_url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false®ion=us" % add | |
req = urllib2.urlopen(geocode_url) | |
jsonResponse = json.loads(req.read()) | |
# pprint.pprint(jsonResponse) | |
try: | |
lat = jsonResponse['results'][0]['geometry']['location']['lat'] | |
lon = jsonResponse['results'][0]['geometry']['location']['lng'] | |
return lat, lon | |
except IndexError: | |
return '', '' | |
print geocode('123 Main St. Presque Isle ME 04769') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment