之前为了获取用户当前位置,我使用了LocationManager:
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
很容易阅读且非常直接的代码。 但是我注意到 Google 最近发布了 Google Play 服务中的新客户端 API 模型,并建议使用 FusedLocationProviderApi,这看起来更加复杂,它是异步的,需要处理回调等。 使用 FusedLocationProviderApi 是否有任何优势比 LocationManager 更好?