对于 Google 地方信息 2019 更新,无法在 setTypeFilter() 中使用两个 typeFilters

问题描述 投票:0回答:2

我已使用以下方式升级到新的 Google 地方信息:

'com.google.android.libraries.places:places:2.0.0'

我在布局中实现了 AutoCompleteSupportFragment,用户将在该片段中输入其位置或目的地。然后信息将被放入BottomSheetRiderFragment中。

我希望能够使用地址和机构进行过滤,但我无法在单独的行上同时执行这两项操作以使其正常工作。

通过研究(关于这个主题的并不是很多),提到了使用

TYPE_FILTER_ADDRESS|TYPE_FILTER_ESTABLISHMENT

我尝试放置:

places_location.setTypeFilter(TYPE_FILTER_ADDRESS|TYPE_FILTER_ESTABLISHMENT);

但是发生了这个错误

setType Filter(com.google.android.libraries.places.api.model.Type Filter) in AutocompleteSupportFragment cannot be applied to (int)

我该如何解决这个问题?

布局

<fragment
                android:id="@+id/places_location"
                android:layout_weight="5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />

<fragment
                android:id="@+id/places_destination"
                android:layout_weight="5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"/>

活动

places_location.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(@NonNull Place place) {
            // Get info about the selected place.
            Log.e(TAG, "Place: " + place.getName() + ", " + place.getId());

            mPlaceLocation = place.getAddress();
        }

        @Override
        public void onError(@NonNull Status status) {
            // Handle the error.
            Log.e(TAG, "An error occurred: " + status);
        }
    });


places_destination.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(@NonNull Place place) {
            // Get info about the selected place.
            Log.e(TAG, "Place: " + place.getName() + ", " + place.getId());

            mPlaceDestination = place.getAddress(); // search bar destination
            Log.e(TAG, "mPlaceDestination = " + mPlaceDestination);

            // search_bar_destination ....
            search_bar_destination = mPlaceDestination;

            // Show information at bottom
            BottomSheetRiderFragment mBottomSheet = BottomSheetRiderFragment
                    .newInstance(mPlaceLocation, mPlaceDestination, false);
            RiderHome.super.onPostResume();
            mBottomSheet.show(getSupportFragmentManager(), mBottomSheet.getTag());
        }

        @Override
        public void onError(@NonNull Status status) {
            // Handle the error.
            Log.e(TAG, "An error occurred: " + status);
        }
    });

还有

// Create a RectangularBounds object.
RectangularBounds bounds = RectangularBounds.newInstance(
    new LatLng(45.282785, -66.235011),
    new LatLng(45.333059, -65.842197));

places_location.setCountry("ca");
places_location.setLocationBias(bounds);
places_location.setTypeFilter(TypeFilter.REGIONS);
places_location.setTypeFilter(TypeFilter.CITIES);
places_location.setTypeFilter(TYPE_FILTER_ADDRESS|TYPE_FILTER_ESTABLISHMENT);
java android google-places-api
2个回答
1
投票

你不能写多个过滤器,如果你写了两个过滤器将不起作用,如果你想要同时建立和地址那么就不要写任何过滤器,因为两者同时不起作用。如果您只想获得附近位置的建议,那么位置偏差非常适合您,它会在建议中为您提供地址和设施

RectangularBounds bounds = RectangularBounds.newInstance
(new LatLng(45.282785, -66.235011),new LatLng(45.333059, -65.842197));
places_location.setCountry("ca");
places_location.setLocationBias(bounds);

0
投票

setTypeFilter
现已被弃用,并替换为
setTypesFilter(List<String> placeTypes)
,它最多需要 5 个地点类型,所以现在有一种方法可以实现这一点。

这是有关它的文档。

© www.soinside.com 2019 - 2024. All rights reserved.