我的情况:
- 首先,我在我的应用中实现了 Google Plus 身份验证。我按照快速启动说明将快速启动示例应用程序代码添加到我的应用程序中。
- 然后我想获取用户的最后一个已知位置。Fused Location Provider 似乎是获取它的最现代方式,所以我查看了LocationUpdates.zip和kpbird 的演示代码。
我的顾虑:
com.google.android.gms.common.api.GoogleApiClient
and命名空间引入了一些重叠,com.google.android.gms.common.GooglePlayServicesClient
因为如果你想使用GoogleApiClient
andLocationClient
,那么你的类(即Activity
)必须实现以下内容:GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener
来自两个命名空间的代码将覆盖以下内容:
@Override
public void onConnected(Bundle connectionHint) {
/* pseudo-code
if (GoogleApiClient) {
// Implementation
} else {
// Must be LocationClient
}
*/
}
@Override
public void onConnectionFailed(ConnectionResult result) {
/* pseudo-code
if (GoogleApiClient) {
// Implementation
} else {
// Must be LocationClient
}
*/
}
这样您将被迫编写代码来辨别是触发了事件处理程序GoogleApiClient
还是LocationClient
触发onConnected
了onConnectionFailed
事件处理程序。
我的问题:
- 我想保持关注点分离。有没有更好的方法来解决这个问题?