import urllib
import json
serviceurl='https//maps.googleapis.com/maps/api/geocode/json?'
while True:
address=input('Enter location: ')
if len(address)<1 :
break
url =serviceurl+urllib.parse.urlencode({'sensor':'false','address':address})
print('retriving',url)
uh=urllib.request.urlopen(url)
data=uh.read().decode('utf8')
print ('Retrieved',len(data),'characters')
try:
js=json.loads(str(data))
except:
json=None
if 'status' not in js or js['status'] !='OK' :
print('fail~~')
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)
print(location)我正在访问谷歌的GeoJSON API。"uh=urllib.request.urlopen( url )“发生错误,无法打开url。我的代码有什么问题?
发布于 2016-02-06 05:31:21
在:之后,您错过了https
https://maps.googleapis.com/maps/api/geocode/json?
HERE^https://stackoverflow.com/questions/35237731
复制相似问题