首页 > 解决方案 > 设置 Autocompleteplace setupAutocompleteTextView

问题描述

我在 setupAutocompleteTextView 上遇到了 Google Maps Place API 的问题

mAdapter = new PlaceAutocompleteAdapter(this, googleApiClient, BOUNDS, null);

    pickUpText.setAdapter(mAdapter);
    pickUpText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager inputManager =
                    (InputMethodManager) GoCabActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(pickUpText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            AutocompletePrediction item = mAdapter.getItem(position);

            getLocationFromPlaceId(item.getPlaceId(), new ResultCallback<PlaceBuffer>() {
                @Override
                public void onResult(@NonNull PlaceBuffer places) {
                    final Place place = places.get(0);
                    LatLng latLng = place.getLatLng();
                    if (latLng != null) {
                        gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                        onPickUpClick();
                    }
                }
            });

        }
    });
    destinationText.setAdapter(mAdapter);
    destinationText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager inputManager =
                    (InputMethodManager) GoCabActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(destinationText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            AutocompletePrediction item = mAdapter.getItem(position);

            getLocationFromPlaceId(item.getPlaceId(), new ResultCallback<PlaceBuffer>() {
                @Override
                public void onResult(@NonNull PlaceBuffer places) {
                    final Place place = places.get(0);
                    LatLng latLng = place.getLatLng();
                    if (latLng != null) {
                        gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                        onDestinationClick();

                    }
                }
            });
        }
    });

logcat 上没有错误,但该功能仍然无法正常工作

标签: javaandroid

解决方案


我正在做一个与您类似的项目,自动完成功能的问题从Googlemap开始, 它已更新到新版本,并且使用 Map 所需的位置 API已过时,并且已经以不同方式重新设计。

您需要做的是更新依赖项。其次,添加新的地方自动完成功能


推荐阅读