【发布时间】:2014-03-29 16:27:08
【问题描述】:
我的情况:
- 首先,我在我的应用程序中实现了 Google Plus 身份验证。我关注了quick start instructions 并将quick start sample app code 添加到我的应用中。
- 然后我想获取用户的最后一个已知位置。 Fused Location Provider 似乎是最现代的获取方式,所以我查看了 LocationUpdates.zip 和 kpbird's demo code。
我的担心:
-
com.google.android.gms.common.api.GoogleApiClient和com.google.android.gms.common.GooglePlayServicesClient命名空间引入了一些重叠,因为如果你想使用GoogleApiClient和LocationClient,那么你的类(即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 事件处理程序。
我的问题:
- 我想保留一个separation of concerns。有没有更好的方法来解决这个问题?
【问题讨论】:
-
看看stackoverflow.com/questions/31734567/… 不是完全解决你的问题,但可能会给你一些想法。
标签: android google-play-services separation-of-concerns google-api-client location-client