1

I have been trying to get similar types of places using google places api. Here's code

/**
     * Method to search certain type of place using Places API
     * Uses latitude and longitude from global variable
     */
    private void getPlaces() {
        apiList = getResources().getStringArray(R.array.apiList);
        int randomIndex = new Random().nextInt(apiList.length);
        String api = apiList[randomIndex];
        String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" +
                latitude + "," + longitude + "&rankby=distance&type=" + type + "&key=" + api;

        Log.i("PlaceList", "url: " + url);

        final RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new com.android.volley.Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Places place;
                        Log.i("PlaceList", "onResponse: response: " + response.toString());
                        try {
                            JSONArray jsonArray = response.getJSONArray("results");
                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject jsonObject = jsonArray.getJSONObject(i);
                                JSONObject geometry = jsonObject.getJSONObject("geometry");
                                JSONObject location = geometry.getJSONObject("location");
                                double lat = location.getDouble("lat");
                                double lng = location.getDouble("lng");
                                String id = jsonObject.getString("id");
                                String name = jsonObject.getString("name");
                                String placeId = jsonObject.getString("place_id");
                                double rating = 0.0;
                                if (jsonObject.has("rating")) {
                                    rating = jsonObject.getDouble("rating");
                                }
                                String vicinity = jsonObject.getString("vicinity");

                                String photoReference = "null";
                                if (jsonObject.has("photos")) {
                                    JSONArray photos = jsonObject.getJSONArray("photos");
                                    JSONObject photosObject = photos.getJSONObject(0);
                                    photoReference = photosObject.getString("photo_reference");
                                }

                                place = new Places(lat, lng, id, name, placeId, rating, photoReference, vicinity);
                                placeArrayList.add(place);
                                Log.i(TAG, "onResponse: palceArrayList: " + placeArrayList.toString());

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        placeListAdapter.notifyDataSetChanged();
                        dialog.dismiss();
                    }
                }, new com.android.volley.Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e(TAG, "onErrorResponse: error: " + error.toString());
                    }
                });
        requestQueue.add(jsonObjectRequest);
    }

I am always getting api quote exceeds error so I tried using multiple api using string-array . No matter what I am unable to get data, I have tried creating new gmail and api which doesn't works. So what am I doing wrong?

Please help. I am beginner so sorry if I have done something wrong please point that mistake, I will correct.

Thank you.

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
DoeJ
  • 405
  • 1
  • 4
  • 14

2 Answers2

1

Try making a new project within the same developer account and enable PLACES API and MAP JAVASCRIPT API. It should work then.

Sakhi Mansoor
  • 7,832
  • 5
  • 22
  • 37
  • I don't know how but your idea worked. Can you explain why enabling JS API did job for me? – DoeJ Aug 26 '18 at 09:47
  • Whenever we use google maps API key we need to able required API restrictions to specify which APIs can be called with this key. It is useful for analytics and quota exceeding for google. – Sakhi Mansoor Aug 26 '18 at 09:54
0

You have exceeded your Google API quota for this API.

I see you are using the Places - Nearby API (https://developers.google.com/places/web-service/search#PlaceSearchRequests).

The current limits and rates can be found here: https://developers.google.com/places/web-service/usage-and-billing

Nick Duncan
  • 829
  • 6
  • 17