I am writing an application trying to retrieve the current location using the Google Place API . But I get the following error log:
E/AndroidRuntime(20212): java.lang.IllegalArgumentException: GoogleApiClient is not configured to use the API required for this call.
E/AndroidRuntime(20212): at com.google.android.gms.common.internal.zzx.zzb(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.internal.zzli.zza(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.location.places.internal.zzj.getCurrentPlace(Unknown Source)
E/AndroidRuntime(20212): at ala.youngashram.droid.com.ala.ALaActivity.getCurrentLocation(ALaActivity.java:266)
E/AndroidRuntime(20212): at ala.youngashram.droid.com.ala.ALaActivity.onConnected(ALaActivity.java:149)
E/AndroidRuntime(20212): at com.google.android.gms.common.internal.zzk.zzh(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.internal.zzlg.zznU(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.internal.zzlg.onConnected(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.internal.zzli$2.onConnected(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.common.internal.zzj$zzg.zzpf(Unknown Source)
E/AndroidRuntime(20212): at com.google.android.gms.common.internal.zzj$zza.zzc(Unknown Source)
Any suggestion that I'm missing here is what I need to tweak to get this!
Updated working code: Thanks @ProblemSlover for sharing the link .
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
This is a connection request:
mGoogleApiClient.connect();
and after receiving the location, call it as soon as you have successfully connected:
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer placeLikelihoods) {
for (PlaceLikelihood placeLikelihood : placeLikelihoods) {
log(String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
placeLikelihoods.release();
}
});
source
share