0

I'm trying to implement Google Play Service Location APIs to use localization in my APP.

protected void createLocationRequest() {

    // Create an instance of GoogleAPIClient.
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }

    LocationRequest mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(10000);
    mLocationRequest.setFastestInterval(5000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequest);

    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());

    final LocationSettingsStates states = result.getLocationSettingsStates();

}

I suppose to already import all needed libraries, anyway AndroidStudio notify to 'Cannot resolve method getLocationSettingsStates()'. I does not get other error. I can't figure out about this.

F.M.
  • 243
  • 2
  • 8
  • 23

1 Answers1

0

result is a PendingResult<LocationSettingsResult>, not a LocationSettingsResult itself which implements getLocationSettingsStates(). You need to do something like:

result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
    @Override
    public void onResult(LocationSettingsResult result) {
      final Status status = result.getStatus();
      final LocationSettingsStates states = result.getLocationSettingsStates();
      // Call states.isBlePresent(), etc.
grantpatterson
  • 405
  • 3
  • 11