AutocompleteActivity Google Places API onActivityResult没有任何反应

时间:2019-03-07 22:40:00

标签: android

我遵循了本指南,以实现placesautocomplete

https://developers.google.com/places/android-sdk/autocomplete

我遵循意图而不是片段。选择地点后没有任何反应。当我点击某个地方时,它只会显示这张图片:

enter image description here

我尝试实现片段版本,但还是一样。什么都没发生。

@OnClick(R.id.editText) void searchLocation() {
        List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
        Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).setTypeFilter(TypeFilter.ADDRESS).setCountry("PH").build(this);
        startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
    }

   @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        switch (requestCode) {
            case REQUEST_CHECK_SETTINGS:
                displayLocationSettingsRequest(getApplicationContext());
                break;
            case AUTOCOMPLETE_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    Place place = Autocomplete.getPlaceFromIntent(data);
                    LatLng latLng = place.getLatLng();
                    String address = place.getAddress();
                    if (getIntent().getIntExtra("switch", 0) == 0) {
                        returnIntent.putExtra("pickup", address);
                        returnIntent.putExtra("latlng", latLng);
                    } else {
                        returnIntent.putExtra("dropoff", address);
                        returnIntent.putExtra("latlng", latLng);
                    }
                    selectedAddress = address;
                    editText.setText(address);
                    location.setText(address);
                    Toast.makeText(getApplicationContext(), address, Toast.LENGTH_SHORT).show();
                } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
                    Status status = Autocomplete.getStatusFromIntent(data);
                    Toast.makeText(getApplicationContext(), status.toString(), Toast.LENGTH_SHORT).show();
                } else if (resultCode == RESULT_CANCELED) {
                    // The user canceled the operation.
                    Toast.makeText(getApplicationContext(), "CANCELLED", Toast.LENGTH_SHORT).show();
                }
        }
    }

我被迫取消操作,因为选择地点没有做任何事情,因此resultcode始终返回RESULT_CANCELLED

0 个答案:

没有答案