当前位置: 代码迷 >> java >> 如何解决初始化 google new AutocompleteSupportFragment (google places) 中的多个错误
  详细解决方案

如何解决初始化 google new AutocompleteSupportFragment (google places) 中的多个错误

热度:125   发布时间:2023-07-31 13:42:01.0

我正在尝试迁移到新的地方 SDK。 我已成功将所有库添加到我的应用程序级 build.gradle,并更新了我的 XML 片段。 但是,初始化 AutocompleteSupportFragment 的代码实现有多个未解决的错误。 我已经尽我所能,但无济于事。 请帮忙

我对编程很陌生。 我尝试按照这里的步骤它没有解决我的任何问题。

isInitialized() 无法解析。

无法解析符号“字段”和

TAG 具有私有访问关注了此

然后又收到另一个错误提示:AutocompleteSupportFragment 中的 setOnPlaceSelectListner 不能应用到(匿名 com.google.android.gms.location.places.ui.PlaceSelectionListner)。

if (!Places.isInitialized()) {
            Places.initialize(getApplicationContext(), "your api key");
        }

// Initialize the AutocompleteSupportFragment.
        AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);

        autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

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

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

我希望我的谷歌搜索能像往常一样工作,但它仍然无法读取我的地点 API。 旧的地方 SDK 出现此错误 (Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED,resolution=null})

现在已经解决了。 问题和解决方案如下:

问题,我在我的应用程序级别 gradle 中有错误的实现

实现 'com.google.android.libraries.places:places-compat:1.0.0'

解决方案删除兼容实现 'com.google.android.libraries.places:places:1.0.0'

  相关解决方案