Android播放服务6.5:缺少LocationClient

Vol*_*man 45 android location google-play-services android-geofence fusedlocationproviderapi

更新到Google Play Services 6.5.87后,由于缺少LocationCLient类,我的应用程序无法编译.

文档链接 是在瞬间损坏(404未找到)

我该如何解决?我想收到位置更新,使用地理围栏等.

ian*_*ake 56

LocationClient类已被新的FusedLocationProviderApiGeofencingApi取代,两者都使用常见的GoogleApiClient连接技术连接到Google Play服务.连接后,可以调用requestLocationUpdates()等方法:

LocationRequest locationRequest = LocationRequest.create()
    .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

PendingResult<Status> result = LocationServices.FusedLocationApi
    .requestLocationUpdates(
        googleApiClient,   // your connected GoogleApiClient
        locationRequest,   // a request to receive a new location
        locationListener); // the listener which will receive updated locations

// Callback is asynchronous. Use await() on a background thread or listen for
// the ResultCallback
result.setResultCallback(new ResultCallback<Status>() {
    void onResult(Status status) {
        if (status.isSuccess()) {
            // Successfully registered
        } else if (status.hasResolution()) {
            // Google provides a way to fix the issue
            status.startResolutionForResult(
                activity,     // your current activity used to receive the result
                RESULT_CODE); // the result code you'll look for in your
                              // onActivityResult method to retry registering
        } else {
            // No recovery. Weep softly or inform the user.
            Log.e(TAG, "Registering failed: " + status.getStatusMessage());
        }
   }
});
Run Code Online (Sandbox Code Playgroud)

  • @Alchete - 针对以前版本的Google Play Services SDK编译的应用程序将继续有效(这可以很容易地验证,因为每部手机都有6.5但不是每个应用都更新到新的API) (6认同)
  • 我真的希望谷歌会更新他们的文档.他们网站上的示例LocationProvider应用程序不再有效:https://developer.android.com/training/location/location-testing.html (5认同)
  • 谢谢!看起来他们更新了服务但忘记更新文档. (3认同)
  • @Simon - 最新的Google Location样本可以在[Github]上找到(https://github.com/googlesamples/android-play-location).不确定为什么开发者网站上的示例仍指向旧版本. (2认同)