Skip to content

Instantly share code, notes, and snippets.

@rainzoo
Created March 27, 2011 20:12
Show Gist options
  • Select an option

  • Save rainzoo/889563 to your computer and use it in GitHub Desktop.

Select an option

Save rainzoo/889563 to your computer and use it in GitHub Desktop.
Latitude and Longitude of the address using Google Maps Gecoding API
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