如何收听AutocompleteSupportFragment没有结果响应

时间:2019-03-03 09:16:18

标签: android google-maps

我正在尝试学习如何使用AutocompleteSupportFragment,但是我发现PlaceSelectionListener仅具有onPlaceSelectedonError方法,但没有提供找不到位置时调用。 我该如何收听no result found

下面是我的代码

if ( !Places.isInitialized() ) {
    Places.initialize( getApplicationContext(), getString( R.string.GOOGLE_MAPS_API_KEY ) );
    autoCompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager()
            .findFragmentById( R.id.autoCompleteFragment );
    autoCompleteFragment.setHint( getString( R.string.search_address_hint ) );
    autoCompleteFragment.setPlaceFields( Arrays.asList( Place.Field.ID,
            Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG ) );
    autoCompleteFragment.setCountry( "ZM" );


    btnConfirm.setOnClickListener( v -> confirmAddress() );

    autoCompleteFragment.setOnPlaceSelectedListener( new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            edtBuilding.setText( place.getName() );
            startIntentService( place.getLatLng() );
            adjustCamera( place.getLatLng() );
            mPresenter.addMarker( place.getLatLng(), place.getName(), place.getAddress(), ConfirmPickUpActivity.MARKER_NORMAL );
        }

        @Override
        public void onError(Status status) {
            Log.i( TAG, "An error occurred: " + status );
        }
    } );
}

1 个答案:

答案 0 :(得分:0)

您可能错过了此页面。 https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesStatusCodes

它在那里,状态码Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) { return Column( children:[ Expanded( child: ListView( padding: const EdgeInsets.only(top: 10.0), children: snapshot.map((data) => _buildListItem(context, data)).toList(), ),), RaisedButton( // fill in required params ) ] } 。在您的代码中,您必须编写。

NOT_FOUND