自动完成地点时出现错误:OVER_QUERY_LIMIT

8

当我尝试在Place Autocomplete中搜索时,出现了无法加载搜索结果的错误信息,日志显示:

"自动完成时出错:OVER_QUERY_LIMIT"

我已经开启了https://console.cloud.google.com/并且API密钥也正常工作。

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>
3个回答

12
您收到“OVER_QUERY_LIMIT”消息,因为您尚未为项目启用结算开发者控制台中。

要使用Android Places SDK,您必须在所有API请求中包含一个API密钥,并且您必须在每个项目上启用结算

查看此链接以获取更多信息和定价。

SKU:基础数据

基础类别中的字段包含在Places请求的基本成本中,并且不会导致任何额外费用。任何请求这些字段之一时,都会触发Basic Data SKU:ADDRESS、ID、LAT_LNG、NAME、OPENING_HOURS、PHOTO_METADATAS、PLUS_CODE、TYPES、USER_RATINGS_TOTAL、VIEWPORT。

您可以在上述相同链接中查看定价和其他SKU。


1
伙计,这很难,任何与计费相关的事情。 - Idris Stack

2
OVER_QUERY_LIMIT 表示您已超过使用配额限制。主要原因如下:
如果您超出使用限制,您将收到一个 OVER_QUERY_LIMIT 状态码作为响应。这意味着 Web 服务将停止提供正常响应,并切换到仅返回状态码 OVER_QUERY_LIMIT,直到再次允许更多使用。这可能发生在以下情况下:
1. 如果错误是由于您的应用程序每秒发送了太多请求而接收到的,则在几秒钟内。 2. 如果错误是由于您的应用程序每天发送了太多请求而接收到的,则在接下来的 24 小时内。每日配额在太平洋时间午夜重置。
您也可以查看此处获取更多详细信息。

谢谢你的帮助,但我从第一天开始就无法使用它,我该如何使用我的限制? - AhmedEssam
为了增加使用限制,您需要拥有付费账户。您必须支付更新限制的费用。 - Faysal Ahmed
很遗憾 :( ,谢谢你的帮助 ^_^ - AhmedEssam
更多信息请参阅:https://developers.google.com/maps/documentation/directions/usage-and-billing - Faysal Ahmed

0

如果您正在使用已弃用的Play Services版本的Places SDK com.google.android.gms:play-services-places,则会收到PLACES_API_RATE_LIMIT_EXCEEDED错误,如此处所述:

注意:如果您的Android应用程序遇到9005 PLACES_API_RATE_LIMIT_EXCEEDED错误,则可能正在使用已弃用的Android Places SDK版本。例如,Google Play服务版本的Android Places SDK(例如com.google.android.gms:play-services-places)已于2019年1月29日停用,并于2019年7月29日关闭。现在提供了Android Places SDK的新版本。我们建议尽快更新到新版本。有关详细信息,请参阅迁移指南。

您必须在build.gradle中替换以下行:

implementation 'com.google.android.gms:play-services-places:<VERSION>'

使用:

implementation 'com.google.android.libraries.places:places:2.2.0'

请注意,版本2或更高版本需要androidx。在撰写本文时,最新版本不需要androidx的版本是1.1.0。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接