Last active
August 29, 2015 14:09
-
-
Save jumbojet/a6f3f92309da6a990a36 to your computer and use it in GitHub Desktop.
Geo Location API Call
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 json, urllib | |
def get_latitude_longitude(address): | |
# assuming address object contains all the reuqried address fields | |
location = str(address.addressLine) +"+" +str(address.locality)+"+"+str(address.city)+ | |
"+"+ str(address.state)+"+"+str(address.country)+"+"+str(address.zipCode) | |
GEOLOC_URL = 'http://maps.googleapis.com/maps/api/geocode/json' | |
GEO_ARGS = {} | |
GEO_ARGS.update({'address': loc }) | |
url = GEOLOC_URL + '?' + urllib.urlencode(GEO_ARGS) | |
result = json.load(urllib.urlopen(url)) | |
latitude = result['results'][0]['geometry']['location']['lat'] | |
longitude = result['results'][0]['geometry']['location']['lng'] | |
return (latitude,longitude,) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment