我尝试集成Google地方信息自动填充功能,最初运行良好,但从昨天开始,它的运行方式就很特殊。
有时它根本不加载搜索结果:
无论何时(偶尔),如果我尝试从搜索结果中选择一个地点,而不是选择该地点,它都会重新开始搜索。
我在这里收到建议
Screenshot when it actually shows suggestions sometimes
我选择了代托纳比奇(Daytona Beach),而不是选择它就开始搜索它,但未显示任何结果
Screenshot after I selected a place from the suggestions, it starts searching for it again
这就是我所做的:
1)在应用程序级别gradle文件中
implementation 'com.google.android.libraries.places:places:1.1.0'
2)代码
Places.initialize(MainActivity.this, getResources().getString(R.string.api_key));
autocompleteFragment = (AutocompleteSupportFragment)getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS_COMPONENTS,
Place.Field.ADDRESS, Place.Field.LAT_LNG));
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i("TESTPLACEE", "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("TESTPLACEE", "An error occurred: " + status);
}
});