Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- import json
- serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
- while True:
- address = raw_input('Enter location: ')
- if len(address) < 1 : break
- url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
- uh = urllib.urlopen(url)
- data = uh.read()
- try: js = json.loads(str(data))
- except: js = None
- if 'status' not in js or js['status'] != 'OK':
- print '==== Failure To Retrieve ===='
- print data
- continue
- print json.dumps(js, indent=4)
- lat = js["results"][0]["geometry"]["location"]["lat"]
- lng = js["results"][0]["geometry"]["location"]["lng"]
- print 'lat',lat,'lng',lng
- shortlock = js["results"][0]["address_components"]["short_name"]
- print shortlock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement