【问题标题】:Google Places API quota exceed [duplicate]Google Places API 配额超出 [重复]
【发布时间】:2023-03-24 01:24:01
【问题描述】:

我一直在尝试使用 google places api 获得类似类型的地方。 这是代码

/**
     * 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);
    }

我总是收到 api 引用超出错误,所以我尝试使用多个 api 使用字符串数组 .无论我无法获取数据,我都尝试创建不起作用的新 gmail 和 api。那我做错了什么?

请帮忙。我是初学者,如果我做错了什么,请指出错误,我会纠正。

谢谢。

【问题讨论】:

    标签: android google-maps google-places-api google-places


    【解决方案1】:

    尝试在同一个开发者帐户中创建一个新项目并启用 PLACES API 和 MAP JAVASCRIPT API。那么它应该可以工作了。

    【讨论】:

    • 我不知道你的想法是如何奏效的。你能解释一下为什么启用 JS API 对我有用吗?
    • 每当我们使用 google maps API 密钥时,我们都需要有必要的 API 限制来指定可以使用该密钥调用哪些 API。这对于 google 的分析和配额超出非常有用。
    【解决方案2】:

    您已超出此 API 的 Google API 配额。

    我看到您正在使用 Places - Nearby API (https://developers.google.com/places/web-service/search#PlaceSearchRequests)。

    可以在此处找到当前的限制和费率:https://developers.google.com/places/web-service/usage-and-billing

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多