Google Places API配额超过 [英] Google Places API quota exceed

查看:77
本文介绍了Google Places API配额超过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Google Places API获得类似类型的地方. 这是代码

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

我一直在获取api引用超出错误,因此我尝试使用字符串数组使用多个api .无论我无法获取什么数据,我都尝试创建不起作用的新gmail和api.那我在做什么错了?

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.

谢谢.

推荐答案

尝试在同一开发人员帐户中创建一个新项目,并启用PLACES API和MAP JAVASCRIPT API.这样就可以了.

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

这篇关于Google Places API配额超过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆