android - 为什么要使用 GoogleAPIClient 来请求位置更新?

标签 android android-mapview android-maps-v2 android-location android-googleapiclient

我注意到可以(至少)以两种不同的方式请求位置更新。

  1. 使用 GoogleAPIClient:

    // Callback for when the GoogleAPIClient is connected
    @Override
    public void onConnected(Bundle connectionHint) {
        LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);
    }
    

  1. 使用 LocationManager:

    LocationManager locationManager = (LocationManager) getActivity().
        getSystemService(Context.LOCATION_SERVICE);      
    
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 
        0, 0, locationListener);
    

Google 似乎在他们的教程 "Receiving Location Updates" 中推广了方法 1 .我不清楚方法 1 的好处是什么,因为方法 2 对我来说同样有效(我在应用程序的两个不同位置使用这两种方法).

最佳答案

好消息,从 Google Play 服务版本 11.0 开始,无需连接 GoogleApiClient

https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html

您不必处理回调和状态(已连接、正在连接),只需请求/删除位置更新,与 LocationManager 类似。

关于android - 为什么要使用 GoogleAPIClient 来请求位置更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37499479/

相关文章:

java - 黑屏 Android 2.2 Google map v2

android - 单击 InfoWindows 的突出显示时禁用?

android - Firebase 身份验证 : Google sign in pop up window doesn't show up again once after I sign in with an acccount

android - 在 MapView-Android 中使用 LocationName 为某个位置设置动画

android - 将构建配置值添加到 list 元数据

android - 在 Android 上向 MapView 添加单个叠加层

android - 以编程方式增加android map 缩放级别

android - 如何远程调试webview?

java - 在另一个对话框的单击事件中创建对话框的问题

java.lang.StackOverflowError : stack size 8MB in Views 错误