PlacePicker closes immidiately , migrating from Places SDK for Android to Google Places API causing error

我与影子孤独终老i 提交于 2019-12-13 02:48:56

问题


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.

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

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.

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();
        }
    });

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);
    }
}

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/56029941/placepicker-closes-immidiately-migrating-from-places-sdk-for-android-to-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!