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

问题描述 投票:-2回答:1

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

我对编程很陌生。我尝试按照这里的步骤http://errorstrike.com/2019/02/places-autocomplete-error-fix-2019/#respond它没有解决我的任何问题。

isInitialized()无法解析。

无法解析符号'Field'和

TAG有私人访问 - 我跟着这个'TAG' has private access in 'android.support.v4.app.FragmentActivity'

然后又出现了另一个错误: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中遇到此错误(状态{statusCode = PLACES_API_ACCESS_NOT_CONFIGURED,resolution = null})

java android google-places googleplacesautocomplete
1个回答
1
投票

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.