我正在尝试将新的自动完成地点选择器从"com.google.android.gms:play-services"
迁移到新的"com.google.android.libraries.places:places-compat:2.0.0"
,并实现了SupportPlaceAutocompleteFragment
。
一切正常,但是我得到的错误是:
"Place.Field" Cannot resolve symbol 'Field'
下面是我的代码:
// Initialize the AutocompleteSupportFragment.
SupportPlaceAutocompleteFragment supportPlaceAutocompleteFragment = (SupportPlaceAutocompleteFragment)getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show();
Log.i("", "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
}
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
您能帮我解决此错误吗?
"Place.Field" Cannot resolve symbol 'Field'
答案 0 :(得分:0)
SupportPlaceAutocompleteFragment类为deprecated。请改用AutocompleteSupportFragment类。请参阅Google's migration guide和Place Autocomplete's guide。
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment supportPlaceAutocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show();
Log.i("", "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
}
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
希望这会有所帮助!
答案 1 :(得分:0)
确保您导入了正确的Place类。
import com.google.android.libraries.places.api.model.Place;
希望这会有所帮助。