Created
September 24, 2013 17:01
-
-
Save deanohyeah/6687821 to your computer and use it in GitHub Desktop.
python function to use googles geocoding. import requests
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 _geocode(self, address, *args, **kwargs): | |
url = 'http://maps.googleapis.com/maps/api/geocode/json' | |
payload = { | |
'address': address+' '+self.state, | |
'sensor': 'false', | |
} | |
r = requests.get(url, params=payload) | |
if r.status_code == 200: | |
data = r.json | |
print data | |
lat = data['results'][0]['geometry']['location']['lat'] | |
lng = data['results'][0]['geometry']['location']['lng'] | |
return lat, lng | |
return 0, 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment