Created
October 4, 2016 16:11
-
-
Save thomasjk10/78cb6bd1cd04466591aae11794ac326d to your computer and use it in GitHub Desktop.
Geo JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import json | |
# serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?' | |
serviceurl = 'http://python-data.dr-chuck.net/geojson?' | |
while True: | |
address = raw_input('Enter location: ') | |
if len(address) < 1 : break | |
url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address}) | |
print 'Retrieving', url | |
uh = urllib.urlopen(url) | |
data = uh.read() | |
print 'Retrieved',len(data),'characters' | |
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) | |
print js["results"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment