Cannot Resolve Symbol "Place.Field"

I am trying to migrate new Auto Complete Place Picker I have updated library from "com.google.android.gms:play-services" to new "com.google.android.libraries.places:places-compat:2.0.0" and implemented SupportPlaceAutocompleteFragment.

All works fine however the error I am getting is:

"Place.Field" Cannot resolve symbol 'Field'

Below is my code:

 // 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));

Can you help me solve this error:

"Place.Field" Cannot resolve symbol 'Field'

2

2 Answers

Ensure that you import the correct Place class.

import com.google.android.libraries.places.api.model.Place;

Hope this helps.

The SupportPlaceAutocompleteFragment class is deprecated. Please use the AutocompleteSupportFragment class instead. Refer to Google's migration guide and the 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));

Hope this helps!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like