【问题标题】:Google Places API Android: Autocompletion closes too quicklyGoogle Places API Android:自动完成关闭太快
【发布时间】:2017-04-01 03:46:53
【问题描述】:

我在我的 Android 应用中添加了地方自动完成功能。当我单击一个按钮 (chooseLocationButton) 时,它会正确打开自动完成小部件。问题是当我想在搜索字段中写一个名字时。单击第一次击键后,自动完成小部件立即关闭,研究尚未完成。 这是它在运行控制台中所写的:

W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection

代码如下:

AutocompleteFilter.Builder a = new AutocompleteFilter.Builder();
    try {
        final Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                .setFilter(a.setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS).build())
                .build(this);
        chooseLocationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
            }
        });
    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
        // TODO handle exception!
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
        // TODO handle exception! Toast?
    }

当然,我已经在 Google Developer Console 中启用了 Google Places android API 和 Google Map android API。 我还向 AndroidManifest.xml 添加了 API 密钥,如下所示:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

在日志中我观察到:

BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions...

后跟:

[67738] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions?key=...11-17 21:02:01.207 1053-1543/? E/Places: PLACES_API_INVALID_APP

在 Android Studio 的运行日志中我有:PLACES_API_KEY_EXPIRED

我希望有人可以帮助我。

谢谢。

【问题讨论】:

  • 你在manifest的application标签中定义了key吗?
  • 是的,它是在应用程序标签@kgandroid中定义的

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


【解决方案1】:

这听起来确实是一个关键问题。需要仔细检查的事项:

  • 密钥是 Android 密钥,而不是网络密钥。
  • key上的包名restrict实际上和你应用的包名一致,为signed correctly
  • 您没有超过每天 1000 个请求的限制。

【讨论】:

  • 我添加了我在 Google API 控制台中创建的 API 密钥。我使用“Android 应用程序”来限制它,这是我在 AndroidManifest.xml 和 SHA-1 顶部找到的包名称(与您与我共享的网站相同)。每天的请求数量远远超过 1000 个限制@AndrewR
【解决方案2】:

当我注意到 Google 为 API 密钥创建了一个 .xml 文件并与我放入 string.xml 中的 API 产生冲突时,问题就解决了

【讨论】:

    【解决方案3】:

    更改 API 密钥解决了我的问题。

    您可以从here 生成新密钥

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 2013-10-10
      • 1970-01-01
      • 2020-08-12
      • 2014-05-01
      • 2014-10-13
      • 2017-10-02
      • 1970-01-01
      • 2022-06-19
      相关资源
      最近更新 更多