AutocompleteSupportFragment не возвращает результаты - PullRequest
1 голос
/ 13 января 2020

Ниже приведен мой код для справки ... Я последовал этому примеру, приведенному в блоге.

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

    try {

        Places.initialize(mContext, getString(R.string.google_maps_key));
        PlacesClient placesClient = Places.createClient(mContext);

        // Initialize the AutocompleteSupportFragment.
        AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) this.getChildFragmentManager().findFragmentById(R.id.autocomplete_fragment);
        autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG));
        autocompleteFragment.setCountry("IN");
        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                AppLogger.getInstance().e(TAG, "Place: " + place.getName() + ", " + place.getId());
                AppLogger.getInstance().e(TAG, "Lat Long: " + place.getLatLng().latitude + ", " + place.getLatLng().longitude);

                if (mCurrLocationMarker != null) {
                    LatLng locLatLng = place.getLatLng();

                    MarkerOptions markerOptions = new MarkerOptions();
                    markerOptions.position(locLatLng);
                    markerOptions.title("Current Location");
                    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
                    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
                    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(locLatLng, 20));

                    updateDistance(locLatLng);

                    et_address.setText(Globals.getAddress(mContext, locLatLng.latitude, locLatLng.longitude));
                }
            }

            @Override
            public void onError(Status status) {
                AppLogger.getInstance().e(TAG, "An error occurred: " + status);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        AppLogger.getInstance().e(TAG, "Exception: " + e.getLocalizedMessage());
    }

Запуск по приведенному ниже коду

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

    Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields)
            .setTypeFilter(TypeFilter.ADDRESS)
            .build(mContext);
    startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);

Несколько раз дает отличные результаты ... Но в большинстве случаев это дает ошибку, как показано ниже ...

enter image description here

Заранее спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...