import simplejson import urllib import urllib2 from django.utils.encoding import smart_str def get_lat(loc): location = urllib.quote_plus(smart_str(loc)) dd = urllib2.urlopen("http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false" % location).read() ft = simplejson.loads(dd) if ft["status"] == 'OK': lat = str(ft["results"][0]['geometry']['bounds']['northeast']['lat']) lng = str(ft["results"][0]['geometry']['bounds']['northeast']['lng']) print "%s - %s" % (lat, lng)