我有一个Google地方信息自动填充片段,实现方式如下
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getChildFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG));
LatLng center = ((LocationActivity)getActivity()).getLastLocationLatLng();
if (center != null){
LatLng northSide = SphericalUtil.computeOffset(center, 50000, 0);//50,000 meters
LatLng southSide = SphericalUtil.computeOffset(center, 50000, 180);
LatLngBounds bounds = LatLngBounds.builder()
.include(northSide)
.include(southSide)
.build();
autocompleteFragment.setLocationBias(RectangularBounds.newInstance(bounds));
}
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i(GlobalVar.TAG, "Place: " + place.getName() + ", " + place.getId());
selectedLatLng = place.getLatLng();
}
@Override
public void onError(Status status) {
Log.i(GlobalVar.TAG, "An error occurred: " + status);
}
});
此小部件位于BottomNavigationView的片段之一中。
所以BottomNavigiationView->第三个标签->您将看到Google地方搜索
当我单击搜索时,键入并选择一个结果,然后该应用程序将返回第一个选项卡!。
我确实执行了Log.i(GlobalVar.TAG, "Place: " + place.getName() + ", " + place.getId());
,这意味着自动完成功能检索到了结果,但是由于某种原因,父片段(“第三”选项卡)被破坏/分离了
您有什么建议?
谢谢