Android 当我选择SelectPlaceAutoCompleteFragment时,此时会显示此错误

Android 当我选择SelectPlaceAutoCompleteFragment时,此时会显示此错误,android,Android,我的代码 错误: SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(ViewProperty.this); PlaceAutocompleteFragment autocompleteFragment = (Pl

我的代码

错误:

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(ViewProperty.this);


        PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                mMap.clear();
                mMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(place.getName().toString()));
                mMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 12.0f));
            }

            @Override
            public void onError(Status status) {
                Log.w("myApp", status.toString());
            }
        });
  • 为Android启用PlacesSDK
  • 请参阅此链接:

您必须首先初始化google places

:InputMethodManager: startInputInner : InputBindResult == null need restart W/myApp: Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED, resolution=null}

请在谷歌云控制台上创建一个项目,并允许自动完成API
if (!Places.isInitialized()) {
      Places.initialize(context, "GOOGLE PLACES API KEY HERE")
  }