I am trying this code and getting the error in lines starting with lat, lng and location. Can anyone please help?
import urllib.parse
import urllib.request
import json
while True:
address = input('Enter location: ')
if len(address) < 1 : break
serviceurl = 'http://python-data.dr-chuck.net/geojson'
url = serviceurl + '?' + urllib.parse.urlencode({'sensor':'false', 'address': address})
response = urllib.request.urlopen(url)
data = response.readall().decode('utf-8')
js = json.loads(str(data))
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
location = js['results'[0]]['formatted_address']
print(location)
Thanks, Arun