我想使用Google,获取和显示某一地区的餐馆列表。我尝试过这样做,但它没有显示任何内容,也没有错误:
String url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-45.730425,4.839938&radius=500&types=food&key=AIzaSyD8vqYPQzJRJa3rOLSC1wqIaUxSN0WcvGc";
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("json", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("json", "not working");
}
});发布于 2016-11-30 16:09:36
如果您在web浏览器中尝试该URL,它将告诉您问题所在:
{
"error_message": "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/places_backend?project=_",
"html_attributions": [],
"results": [],
"status": "REQUEST_DENIED"
}因此,您似乎还没有在开发人员控制台中启用API。
转到https://console.developers.google.com/
然后单击您想要的项目,在左手菜单中单击API管理器,然后库,搜索顶部的位置,然后单击您想要的结果,从这里您应该会看到一个按钮,上面写着"ENABLE“。
单击它,然后再次尝试您的请求,它应该可以工作。
编辑:
响应中提供了一个链接,供您使用:
单击它,应该有在此页面上启用API的选项。
https://stackoverflow.com/questions/40892912
复制相似问题