Created
March 27, 2011 20:12
-
-
Save rainzoo/889563 to your computer and use it in GitHub Desktop.
Latitude and Longitude of the address using Google Maps Gecoding API
This file contains hidden or 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 urllib2 as u | |
| import json | |
| def GeoCode(address): | |
| """Returns Latitude and Longitude of the address using | |
| Google Maps Gecoding API | |
| """ | |
| api = "http://maps.googleapis.com/maps/api/geocode/json?address=" | |
| address = str(address.replace(" ","+")) | |
| url = api + address + "&sensor=false" | |
| f = u.urlopen(url) | |
| j = f.read() #json | |
| d = json.JSONDecoder() | |
| location = d.decode(j) | |
| l = location['results'][0] #dictionary | |
| lat = str(l['geometry']['location']['lat']) | |
| lng = str(l['geometry']['location']['lng']) | |
| f.close() | |
| return lat,lng |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment