我注意到可以(至少)以两种不同的方式请求位置更新。
使用
GoogleAPIClient
:// Callback for when the GoogleAPIClient is connected @Override public void onConnected(Bundle connectionHint) { LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this); }
使用
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/