【问题标题】:Android play services 6.5: LocationClient is missingAndroid 播放服务 6.5:LocationClient 缺失
【发布时间】:2015-02-06 23:21:02
【问题描述】:

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

documentation link 目前已损坏(404 Not Found)

我该如何解决? 我想接收位置更新、使用地理围栏等。

【问题讨论】:

  • 你说得对。我刚刚发现了同样的问题。

标签: android location google-play-services android-geofence fusedlocationproviderapi


【解决方案1】:

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

【讨论】:

  • 谢谢!看起来他们更新了服务但忘记更新文档了。
  • 我很好奇这对于使用现已删除的 LocationClient API 的现场应用程序意味着什么,以及当用户的手机更新到最新的 Google Play 服务时会发生什么?由于 API 不再编译 - 应用程序会崩溃还是继续工作?
  • @Alchete - 针对以前版本的 Google Play 服务 SDK 编译的应用程序将继续工作(这很容易验证,因为每部手机都有 6.5,但并非每个应用程序都更新到新的 API)跨度>
  • 我真希望谷歌能更新他们的文档。他们网站上的示例 LocationProvider 应用程序不再工作:developer.android.com/training/location/location-testing.html
  • @Simon - 可以在on Github 找到最新的 Google 位置示例。不知道为什么开发者网站上的示例仍然指向旧示例。
猜你喜欢
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 2016-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多