2016-11-30 124 views
-1

我想使用Google Places API来获取并显示某个区域的餐馆列表。 我试过,但它显示什么,我没有错误:JsonObjectRequest什么都不返回

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"); 
       } 
      }); 

回答

0

如果您尝试URL在Web浏览器,它会告诉你是什么问题:

{ 
    "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经理,那么库,搜索,然后点击你想要的结果,从这里你应该看到一个按钮,说“启用”

点击它,然后再次尝试您的请求,它应该工作。

编辑:

的链接在响应为您提供使用方法:

https://console.developers.google.com/apis/api/places_backend

点击这一点,应该启用API此页面上的选项