无法在 setTypeFilter() 中为 Google Places 2019 更新使用两个类型过滤器
Unable to use two typeFilters in setTypeFilter() for Google Places 2019 update
我已经升级到新的 Google 地方使用:
'com.google.android.libraries.places:places:2.0.0'
我在我的布局中实现了一个 AutoCompleteSupportFragment,用户将在该片段中输入他们的位置或目的地。然后信息将被放入 BottomSheetRiderFragment.
我希望能够使用 Addresses 和 Establishments 进行过滤,但我不能在不同的行上同时执行这两项操作才能正常工作。
通过研究(关于这个主题的研究不多),有人提到使用
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"/>
Activity
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);
你不能写一个以上的过滤器,如果你写两个过滤器就不行,如果你既要建立又要地址那么就不要写任何过滤器,因为同时写两个是不行的。如果您只想获得附近位置的建议,那么 Location Bias 非常适合您,它会在建议范围内为您提供地址和机构
RectangularBounds bounds = RectangularBounds.newInstance
(new LatLng(45.282785, -66.235011),new LatLng(45.333059, -65.842197));
places_location.setCountry("ca");
places_location.setLocationBias(bounds);
我已经升级到新的 Google 地方使用:
'com.google.android.libraries.places:places:2.0.0'
我在我的布局中实现了一个 AutoCompleteSupportFragment,用户将在该片段中输入他们的位置或目的地。然后信息将被放入 BottomSheetRiderFragment.
我希望能够使用 Addresses 和 Establishments 进行过滤,但我不能在不同的行上同时执行这两项操作才能正常工作。
通过研究(关于这个主题的研究不多),有人提到使用
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"/>
Activity
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);
你不能写一个以上的过滤器,如果你写两个过滤器就不行,如果你既要建立又要地址那么就不要写任何过滤器,因为同时写两个是不行的。如果您只想获得附近位置的建议,那么 Location Bias 非常适合您,它会在建议范围内为您提供地址和机构
RectangularBounds bounds = RectangularBounds.newInstance
(new LatLng(45.282785, -66.235011),new LatLng(45.333059, -65.842197));
places_location.setCountry("ca");
places_location.setLocationBias(bounds);