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.