我将 Place Autocompletion 添加到我的 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。
另外,我已将 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
我希望有人能帮助我。
谢谢。