hana hana - 1 year ago 96
Android Question

JsonObjectRequest returns nothing

I want to use Google Places API, to fetch and display the list of restaurants in a certain area.
I tried this but it displays nothing, and I have no errors:

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>() {

public void onResponse(JSONObject response) {
Log.d("json", response.toString());
}, new Response.ErrorListener() {

public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("json", "not working");

Answer Source

If you try that URL in a web browser it will tell you what the problem is:

    "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"

So it looks like you haven't enabled the API in the developer console.

Go to https://console.developers.google.com/

And then click on the project you want, in the left hand menu click API manager, then library, search at the top for Places and then click on the result you want, from here you should see a button that says "ENABLE"

Click on that then try your request again and it should work.


A link is provided in the response for you to use:


Click on that and there should be the option to enable the API on this page

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download