首页 > 解决方案 > Google Place Autocomplete 破坏了它所在的父片段

问题描述

我有一个谷歌地方自动完成片段实现如下

    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 的其中一个片段中。

所以底部导航视图->第三个选项卡->你会看到谷歌地方搜索

当我单击搜索、输入并选择其中一个结果时,应用程序会返回到第一个选项卡!

我确实被Log.i(GlobalVar.TAG, "Place: " + place.getName() + ", " + place.getId());执行了,这意味着自动完成检索了结果,但由于某种原因,父片段(第三个选项卡)被破坏/分离

你有什么建议?

谢谢

标签: javaandroidgoogle-mapsgoogle-places-api

解决方案


推荐阅读