Google 地方 API Android: 自动完成关闭得太快
Google Places API Android: Autocompletion closes too quickly
我在我的 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 Places android API and Google Map android API in the Google开发者控制台。
我还像这样将 API 键添加到 AndroidManifest.xml 中:
<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
我希望有人能帮助我。
谢谢。
听起来确实是个关键问题。需要仔细检查的事项:
- 密钥是 Android 密钥,而不是 Web 密钥。
- key上的包名限制和你应用的包名一致,是signed correctly。
- 您没有超过 1000 requests/day 限制。
当我注意到 Google 为 API 键创建了一个 .xml 文件并与我的 API 产生了冲突时,问题就解决了放入 string.xml
更改 API 密钥解决了我的问题。
您可以从 here
生成新密钥
我在我的 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 Places android API and Google Map android API in the Google开发者控制台。 我还像这样将 API 键添加到 AndroidManifest.xml 中:
<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
我希望有人能帮助我。
谢谢。
听起来确实是个关键问题。需要仔细检查的事项:
- 密钥是 Android 密钥,而不是 Web 密钥。
- key上的包名限制和你应用的包名一致,是signed correctly。
- 您没有超过 1000 requests/day 限制。
当我注意到 Google 为 API 键创建了一个 .xml 文件并与我的 API 产生了冲突时,问题就解决了放入 string.xml
更改 API 密钥解决了我的问题。
您可以从 here
生成新密钥