android - 自动完成时放置自动完成错误 : OVER_QUERY_LIMIT

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

当我尝试在“地点自动完成”中搜索时,我得到了无法加载搜索结果 日志说

"Error while autocompleting: OVER_QUERY_LIMIT"

我启用了 https://console.cloud.google.com/ 和 API key 运行良好。

enter image description here

Java代码

    String apiKey = "MY API KEY";
    private RadioGroup mRadioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_costumer_map);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);

        Places.initialize(getApplicationContext(), apiKey);

        PlacesClient placesClient = Places.createClient(this);
          // Initialize the AutocompleteSupportFragment.
        AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        // Specify the types of place data to return.
        autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

        // Set up a PlaceSelectionListener to handle the response.
        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                destination = place.getName().toString();
                destinationLatLng = place.getLatLng();

                Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
            }

            @Override
            public void onError(Status status) {
                Log.e(TAG, "onError: " + status);
            }
        });

XML 代码

       <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:layout_margin="20sp">

        <fragment
            android:id="@+id/place_autocomplete_fragment"
            android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.v7.widget.CardView>

最佳答案

您在 developers console 中收到 OVER_QUERY_LIMIT 消息因为您没有为您的项目启用计费 .

To use the Places SDK for Android, you must include an API key with all API requests and you must enable billing on each of your projects.

检查 this link了解更多信息和定价。

SKU:基本数据

Fields in the Basic category are included in the base cost of the Places request, and do not result in any additional charge. The Basic Data SKU is triggered when any of these fields are requested: ADDRESS, ID, LAT_LNG, NAME, OPENING_HOURS, PHOTO_METADATAS, PLUS_CODE, TYPES, USER_RATINGS_TOTAL, VIEWPORT.

您可以在 same link 中查看定价和其他 SKU。上面给出。

关于android - 自动完成时放置自动完成错误 : OVER_QUERY_LIMIT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54750332/

相关文章:

android - 在 ListView 中将背景设为黄色以获得正确答案

google-maps - 在没有 iframe 的网站上嵌入 map

javascript - 如何在 Biostall Google Maps V3 API 中更改的边界上将自定义变量名称插入到 poerform 中?

javascript - Google map - map 重新加载

swift - 如何在没有 InfoView 的情况下在 GMSMarker 上添加点击事件

java - 如何在 Android 应用程序中有效使用 google place API

android - 在 Google Places API 中传递当前位置(经度和纬度)

javascript - Cordova/Phonegap 摇动手势检测不适用于 ios 模拟器

android - 如何通过 ADB 获取屏幕像素的颜色

M 中撤销权限后的 Android Activity 和 Fragment 生命周期