2016-08-05 10 views
0

Ich versuche Google Play Service Location APIs zu implementieren, um die Lokalisierung in meiner APP zu verwenden.Methode kann nicht aufgelöst werden 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(); 

} 

Ich nehme an, alle benötigten Bibliotheken bereits importieren, ohnehin Android Studio mitteilen zu ‚Kann Methode getLocationSettingsStates nicht lösen()‘. Ich bekomme keinen anderen Fehler. Ich kann darüber nicht herausfinden.

Antwort

0

result ist ein PendingResult<LocationSettingsResult>, kein LocationSettingsResult selbst, der getLocationSettingsStates() implementiert. Sie müssen etwas tun wie:

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. 
Verwandte Themen