Я пытаюсь получить текущий адрес, используя PlaceDetectionClient
.
Но я получаю эту ошибку ..
com.google.android.gms.common.api.ApiException: 13: ERROR
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.common.internal.zai.zaf(Unknown Source)
at com.google.android.gms.common.internal.zaj.onComplete(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.zaa(Unknown Source)
at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source)
at com.google.android.gms.location.places.zzm.zzb(Unknown Source)
at com.google.android.gms.location.places.internal.zzz.dispatchTransaction(Unknown Source)
at com.google.android.gms.internal.places.zzc.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:570)
Вот мой код:
mPlaceDetectionClient = Places.getPlaceDetectionClient(this);
private void showCurrentPlace() {
if (mGoogleMap == null) return;
if (mLocationPermissionGranted) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED)
return;
Task<PlaceLikelihoodBufferResponse> placeResult = mPlaceDetectionClient.getCurrentPlace(null);
placeResult.addOnCompleteListener(new OnCompleteListener<PlaceLikelihoodBufferResponse>() {
@Override
public void onComplete(@NonNull Task<PlaceLikelihoodBufferResponse> task) {
if (task.isSuccessful() && task.getResult() != null) {
PlaceLikelihoodBufferResponse likelyPlaces = task.getResult();
if (likelyPlaces.getCount() > 0) {
sourceTxt.setText(likelyPlaces.get(0).getPlace().getAddress());
}
likelyPlaces.release();
} else Log.e("MainActivity", "RRR Exception: %s", task.getException());
}
});
} else getLocationPermission();
}
И мои gradle
зависимости ...
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'