2016-08-05 138 views
0

我試圖實現Google Play服務位置API以在我的APP中使用本地化。無法解析方法getLocationSettingsStates()

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(); 

} 

我想已經導入所有所需的庫,反正AndroidStudio通知「無法解析法getLocationSettingsStates()」。 我沒有得到其他錯誤。 我不明白這一點。

回答

0

resultPendingResult<LocationSettingsResult>,而不是LocationSettingsResult本身,它實現了getLocationSettingsStates()。您需要執行以下操作:

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.