0

我正在尝试实现 Google Play 服务位置 API 以在我的 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();

}

我想已经导入了所有需要的库,无论如何 AndroidStudio 都会通知“无法解析方法 getLocationSettingsStates()”。我没有收到其他错误。我无法弄清楚这一点。

4

1 回答 1

0

result是 a PendingResult<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.
于 2017-04-12T22:25:06.670 回答