Почему PlaceAutoCompleteFragment не инициирует обратный вызов onPlaceSelected при выборе места? - PullRequest
0 голосов
/ 07 января 2019

Когда я выбираю место в AutoCompleteFragment в моем фиктивном приложении, оно не выбирает место и печатает его имя в logcat, тогда обратный вызов OnPlaceSelected не вызывается и ничего не происходит .tem

Я пытался разместить здесь код Google, но все еще столкнулся с той же проблемой. Я пытался уменьшить версию API с 28 до 25, но это было непреклонно.

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {

private static final String TAG = "GoogleMaps";
private GoogleMap mMap;
PlaceAutocompleteFragment placeAutoComplete;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

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

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            Log.i(TAG, "Place: " + place.getName());
        }

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

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));


}

}

Ожидаемый результат должен быть таким, что выбранное мной место должно быть напечатано в logcat. Пожалуйста, помогите.

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