import json
from StringIO import StringIO
import urllib2
address_geo = 'gandhinagar,india'
url = 'http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false' % address_geo.replace(' ', '+')
response = urllib2.urlopen( url )
responseBody = response.read()
body = StringIO( responseBody )
result = json.load(body)
if 'status' not in result or result['status'] != 'OK' or result['results']==[]:
return False
else:
print result['results'][0]['geometry']['location']['lat']
print result['results'][0]['geometry']['location']['lng']
No comments:
Post a Comment