本文介绍了PlacePicker立即关闭,从Android的Places SDK迁移到Google Places API导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时使用的是Android的旧版Places SDK,但现在它已贬值,因此我尝试使用Google的新版Places SDK.我在compat库中使用了相同的代码,但是一次又一次地出错.

I was using old Places SDK for Android but now its getting depreciated to so i tried to use the new Places SDK from google.I am using the same code with compat library but having some error again and again.

我正在尝试在我的应用中使用Placepicker.我已经为它创建了一个API密钥,并将其添加到我的字符串中.但是,当我打开地点选择器时,它只会崩溃并显示日志

I am trying to use Placepicker in my app. I have created an API key for the same and added to my strings.but when i open the place picker it just crashes with log

Timeline: Activity_launch_request time:126708460 intent:Intent {
act=com.google.android.gms.location.places.ui.PICK_PLACE
pkg=com.google.android.gms (has extras) }

W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection

我已在控制台中启用了我的api,并且我再次检查了它在那儿存在的api密钥.我很困惑这里出了什么问题.

I have enabled my api in the console and i have double checked the api key it exist there. I am confused what is wrong here.

这就是我正在做的事,我使用的是Google文档中提到的以下库,因为它已贬值,所以要使用placepicker.

This is what i am doing, i am using below library as mentioned in the google docs to use placepicker as it has been depreciated.

implementation 'com.google.android.libraries.places:places-compat:1.1.0'

其次,我还要导入文档中提到的以下类

secondly, I am importing below classes as mentioned in the doc as well

import com.google.android.libraries.places.compat.Place;
import com.google.android.libraries.places.compat.ui.PlacePicker;

最后,我在按钮的点击事件中调用了投放机

lastly, i am calling the placekicker on click event of a button

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showPlacePicker();
        }
    });

在我的showPlacePicker中

in my showPlacePicker

int PLACE_PICKER_REQUEST = 1;
private void showPlacePicker() {
    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
    try {
        startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
    } catch (Exception e) {
        Log.e("error", e.getStackTrace().toString());
    }
}


public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);
            LatLng latLng = place.getLatLng();
            lat = latLng.latitude;
            lng = latLng.longitude;
            setAddress();
        }
    }
}

public void setAddress(){
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    try {
        List<Address> addressList = geocoder.getFromLocation(
                lat, lng, 1);
        if (addressList != null && addressList.size() > 0) {
            Address address = addressList.get(0);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                sb.append(address.getAddressLine(i)).append("\n");
            }
            sb.append(address.getFeatureName()).append(", ");
            sb.append(address.getSubLocality()).append(", ");
            sb.append(address.getAdminArea()) ;
            Toast.makeText(this, "admin area"+address.getAdminArea(), Toast.LENGTH_SHORT).show();
            locationText.setText(result);
        }
    } catch (IOException e) {
        Log.e("Address is ", "Unable connect to Geocoder", e);
    }
}

有人可以告诉我这是怎么回事吗?我在这里有点困惑,我在这里没有太多的信息.我已经按照Google上有关获取密钥的步骤进行了操作,还看到了教程.但是我仍然有能力解决这个问题.

Can someone pleaase tell me what wrong here i am a bit confused here i am not getting much info here . I have followed the steps on google about getting the key and saw tutorials as well. But still i am uunable to resolve this.

推荐答案

请注意,自2019年1月29日起,位置选择器已被弃用.此功能将于2019年7月29日关闭,不再启用在该日期之后可用.请注意,使用iOS/Android上的Places SDK的旧用户是唯一在弃用期间仍可以使用Place Picker的用户.现在已通过启用Places API在两个平台上使用Places SDK,并且不再支持使用Place Picker.您可能会在 https://developers.google.com/places/android中看到弃用通知-sdk/placepicker .

Please note that the Place Picker has been deprecated as of January 29, 2019. This feature will be turned off on July 29, 2019, and will no longer be available after that date. Please note that the old users that used Places SDK for iOS/Android are the only one who can still use the Place Picker during the deprecation period. The use of Places SDK for both platforms are now through enabling Places API and does not support the use of Place Picker anymore. You may see the deprecation notice in https://developers.google.com/places/android-sdk/placepicker.

除此以外,Google正在对促使用户使用位置选择器"的因素进行审查,如果您有兴趣,请以此问题.

In addition to this, Google is conducting a review on what drives the users to use the Place Picker, if you are interested, kindly add your answer in the form mentioned in this issue.

这篇关于PlacePicker立即关闭,从Android的Places SDK迁移到Google Places API导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:38