Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Current Place using Google Place API

I'm writing an application where trying to fetch current place using Google Place API. But I'm getting 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 what I'm missing here, what I need to configure to get this!

Updated Working Code: Thanks @ProblemSlover for Sharing link.

mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

This is for connection request:

mGoogleApiClient.connect();

and following to get location, call it once you connected successfully:

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();
            }
        });
like image 649
CoDe Avatar asked Mar 15 '23 12:03

CoDe


1 Answers

Please show us the code you use to configure GoogleApiClient. Please make sure it's done in the proper way as described in the section "Connect to the Places API" on the getting started page. https://developers.google.com/places/android-api/start Here is The config snipped:

// Your activity
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }
like image 97
ProblemSlover Avatar answered Mar 29 '23 02:03

ProblemSlover