Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import urllib
  2. import json
  3.  
  4. serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
  5.  
  6. while True:
  7.     address = raw_input('Enter location: ')
  8.     if len(address) < 1 : break
  9.  
  10.     url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
  11.     uh = urllib.urlopen(url)
  12.     data = uh.read()
  13.    
  14.     try: js = json.loads(str(data))
  15.     except: js = None
  16.     if 'status' not in js or js['status'] != 'OK':
  17.         print '==== Failure To Retrieve ===='
  18.         print data
  19.         continue
  20.  
  21.     print json.dumps(js, indent=4)
  22.  
  23.     lat = js["results"][0]["geometry"]["location"]["lat"]
  24.     lng = js["results"][0]["geometry"]["location"]["lng"]
  25.     print 'lat',lat,'lng',lng
  26.  
  27.     shortlock = js["results"][0]["address_components"]["short_name"]
  28.     print shortlock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement