android – AutocompleteFragment results return a place with null attributes-ThrowExceptions

Exception or error:

I’m trying to make an application with a Navigation Drawer and a Fragment of a Map. I’m trying to have an autocomplete fragment but when i search a place i receive only the name and id attributes.
Like this:

I/PLACE: Place{address=null, attributions=[], id=ChIJVXealLU_xkcRja_At0z9AGY, latLng=null, name=Amsterdam, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}

Here is my MapsFragment

public class MapsFragment extends Fragment implements OnMapReadyCallback, LocationListener {

MapView mapView;
GoogleMap nMap;

AutocompleteSupportFragment autocompleteFragment;
PlacesClient placesClient;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.activity_maps, container, false);

    mapView = (MapView) rootView.findViewById(;


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    autocompleteFragment.onActivityResult(requestCode, resultCode, data);


public void onMapReady(GoogleMap googleMap) {
    Log.i("DEBUG", "onMapReady");

    nMap = googleMap;

    Context mContext = getActivity();
    if (mContext != null){
    Places.initialize(mContext, "*********MY API KEY*********");
        Log.i("PLACE", "ERROR");

    placesClient = Places.createClient(getActivity());

    autocompleteFragment = (AutocompleteSupportFragment)

    autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        public void onPlaceSelected(@NonNull Place place) {
            Log.i("PLACE", place.toString());
            // Define a Place ID.
            //nMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 12.0f));

        public void onError(@NonNull Status status) {
            Log.i("PLACE", status.toString());

    autocompleteFragment.setHint("Select your city");

    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
    } else {
        // Show rationale and request permission.
        Log.d(TAG, "error permission denied");

This i my map.xml

    android:layout_height="56dp" />


        android:layout_height="match_parent" />

I put my API KEY in the code (look map Fragment), in googles_maps_api.xml and also in


Here is my dependencies for google maps

dependencies {
    implementation ''

I follow every steps for activate my API KEY

I also tried to secure my KEY with android restriction but nothing change

My billing system is enable.

How to solve:

you didnt allow in setPlaceFields what do you want.for example i want latlang so i have added LAT_LNG. see below.

 autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.LAT_LNG));


If you want to use addressComponents object, you have to Add Place.Field.ADDRESS_COMPONENTS to the fields list. otherwise this object will be null.


Using same:

List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.ADDRESS,Place.Field.LAT_LNG);

But still given given null value of lat n lng rest value getting i.

Leave a Reply

Your email address will not be published. Required fields are marked *