在Google API控制台中,API访问会为server
,browser
,Android
和iOS
生成密钥。
74.125.129.141
,这可能会改变。 (或者会吗?)我有此代码,显示data
中的result.content
。我的目的是使用ndb.GeoPt(lat,lng)
:
def get_geo(address):
browser_key = "browser_key"
server_key = "server_key"
address = cgi.escape(address.replace(" ","+"))
sensor = "true"
url = "http://maps.googleapis.com/maps/api/geocode/json?key="+ server_key +"&address=" + address + "&sensor="+ sensor
result = urlfetch.fetch(url)
data = json.loads(result.content) # This is the error
geo = data
#lat = data['results'][0]['geometry']['location']['lat']
#long = data['results'][0]['geometry']['location']['lng']
#return ndb.GeoPt(str(lat) +","+ str(long))
return geo
使用上面的示例时出现此错误:
File "C:\xampp\htdocs\mapjobs\main.py", line 18, in get_geo
data = json.loads(result.content)
File "C:\Python27\lib\json\__init__.py", line 310, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 346, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 364, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
答案 0 :(得分:0)
它应包含browser_key
,网址应为:
url = "http://maps.googleapis.com/maps/api/geocode/json?key="+ browser_key +"&address=" + address + "&sensor="+ sensor