【问题标题】:LocationClient class not found on google play services rev 22在 google play services rev 22 上找不到 LocationClient 类
【发布时间】:2014-12-08 19:53:50
【问题描述】:

我刚刚将 google play 服务更新到 rev 22,LocationClient 类似乎丢失了。怎么回事?

【问题讨论】:

  • LocationClient 自夏天以来已被弃用,显然他们现在完全摆脱了它。它有一个新的 API,使用 GoogleApiClient。有关示例应用程序,请参阅 github.com/commonsguy/cw-omnibus/tree/master/Location/FusedNew
  • 感谢您的快速响应!有没有关于如何使用这个新 API 的融合位置的文档?我不知道所以现在我的应用程序现在坏了
  • 上次查看时文档几乎不存在。我不得不从各种来源拼凑我的示例应用程序(以及使用它的书籍章节更新),包括 Stack Overflow 上的其他问题。再说一次,我有一段时间没有找文档了,所以他们可能在我不找的时候发布了教程或其他东西。 :-)
  • 官方培训指南developer.android.com/training/location/retrieve-current.htmlsill 使用LocationClient
  • 谢谢@CommonsWare 我会看看你的 github 示例并进行研究以找到我在这个新 Api 上的方法。我会尽快回复。似乎位置监听器也发生了变化

标签: android google-play-services eclipse-luna


【解决方案1】:

根据@CommnsWare 所说,这里是迁移到 Fused api 的步骤。

第 1 步:获取 GoogleApiClient 的实例,而不是 LocationClient

ConnectionCallback(下面示例中的 mConnectionCallbacks,mOnConnectionFailedListener)需要稍作修改,但这应该是微不足道的。

googleApiClient = new GoogleApiClient.Builder(this)
        .addApi(LocationServices.API)
        .addConnectionCallbacks(mConnectionCallbacks)
        .addOnConnectionFailedListener(mOnConnectionFailedListener)
        .build();

第 2 步:更新连接和断开呼叫。

locationClient.connect() 替换为googleApiClient.connect(),将locationClient.disconnect() 替换为googleApiClient.disconnect()

第 3 步:使用 LocationServices.FusedLocationApi 发送您的请求。 例如

LocationServices.FusedLocationApi.getLastLocation(googleApiClient)
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, mLocationListener);

希望这会有所帮助!

【讨论】:

  • 是的,这也是我刚刚使用@CommonsWare 示例弄清楚的步骤。此外,您只需用 GoogleApiClient.ConnectionCallbacks 替换旧的接口,GoogleApiClient.OnConnectionFailedListener Plus LocationListener 保持不变,只是不再有 onDisconnect 方法
  • 每隔一段时间请求位置更新怎么样? GoogleApiClient 是否仍然支持它?
猜你喜欢
  • 1970-01-01
  • 2013-05-29
  • 1970-01-01
  • 1970-01-01
  • 2014-02-27
  • 2016-09-25
  • 2014-07-24
  • 2018-11-06
  • 1970-01-01
相关资源
最近更新 更多