有没有使用过FusedLocationProviderApi中的LocationManager任何优势? [英] Are there any advantages of using FusedLocationProviderApi over LocationManager?

查看:1083
本文介绍了有没有使用过FusedLocationProviderApi中的LocationManager任何优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此前拿到我用的LocationManager用户当前的位置:

Earlier to get user current location I have used 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);
}

这是很容易阅读和非常简单code。

It is easy to read and very straightforward code.

不过,我已经注意到,谷歌最近发布的在谷歌新的客户端API样板戏服务,并建议使用<一个href=\"https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html\"相对=nofollow> FusedLocationProviderApi 它看起来像要复杂得多,它是异步,它需要处理回调等。

But I have noticed that Google recently released New Client API Model in Google Play Services and suggests to use FusedLocationProviderApi which looks like much more complicated, it is async, it requires to handle callbacks etc.

有没有使用过FusedLocationProviderApi中的LocationManager什么优势?

Are there any advantages of using FusedLocationProviderApi over LocationManager?

推荐答案

FusedLocationProvider使用硬件来确定根据请求的上下文位置的组合,这意味着它是透明的优化给你。它也将高速缓存捕获应用程序之间的位置,以避免不必要的工作来确定位置信息。因此,如果一个用户有多种位置感知应用程序,它们潜在地避免为一个可能已经被高速存储了位置捕获征税的装置(等待)。

FusedLocationProvider uses a mix of hardware to determine location based on the context of the request, meaning it's optimized transparently to you. It will also cache captured locations between applications to avoid unnecessary work to determine location info. So if a user has a variety of location-aware apps, they potentially avoid taxing the device (and waiting) for a location capture as one may have already been cached.

虽然醇'的LocationManager将在小型的,一次性的情况下就足够了,你一定要考虑新的替代的好处可能是巨大的,而且工作来实现,容易的。

While the ol' LocationManager will suffice in small, one-off situations, you should definitely consider the newer alternative as the benefits may be great, and the work to implement, easy.

您不妨将它作为谷歌Play服务跨设备定期更新,不断改进,包括基于位置的功能(及以上)。

You may as well use it as Google Play Services is regularly updated across devices, and continuously includes improvements to location-based features (and more).

在发布的链接FusedLocationProvider的解释: https://www.youtube.com /手表?v = Bte_GHuxUGc

A link to an explanation of the FusedLocationProvider at launch: https://www.youtube.com/watch?v=Bte_GHuxUGc

这篇关于有没有使用过FusedLocationProviderApi中的LocationManager任何优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆