我正在尝试迁移到新的Places SDK。我已成功将所有库添加到应用程序级build.gradle中,并更新了XML片段。但是,初始化AutocompleteSupportFragment的代码实现有多个未解决的错误。我已尽力而为。请帮助
我对编程很陌生。我尝试按照此处的步骤http://errorstrike.com/2019/02/places-autocomplete-error-fix-2019/#respond 它没有解决我的任何问题。
isInitialized()无法解析。
无法解析符号“字段”和
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);
}
});
我希望我的Google搜索能够照常工作,但是仍然无法读取我的Places API。我在旧的地方SDK(状态{statusCode = PLACES_API_ACCESS_NOT_CONFIGURED,resolution = null})下收到此错误
答案 0 :(得分:1)
现在已解决。问题和解决方案如下:
问题,我的应用程序级别gradle中的实现错误
实现'com.google.android.libraries.places:places-compat:1.0.0'
解决方案删除兼容性 实施'com.google.android.libraries.places:places:1.0.0'