Android:在 Android 框架位置 API 上使用 FusedLocationProviderApi 的优缺点是什么?

标签 android google-play-services

Here谷歌说:

The Google Play services location APIs are preferred over the Android framework location APIs (android.location) as a way of adding location awareness to your app. If you are currently using the Android framework location APIs, you are strongly encouraged to switch to the Google Play services location APIs as soon as possible.

谁能向我解释为什么(如果我)需要切换到新的 API?

最佳答案

我认为核心区别在于 FusedLocationProvider 同时使用物理传感器和 google play 服务,而其他(位置管理器/位置列表器)使用 gps 和网络等物理传感器。

FusedLocationProvider

FusedLocationProvider 使用硬件和 google play 服务的组合来找到请求的上下文(位置)。

优点:

  1. 它可以在基于 GPS 和基于 WiFi 的位置之间切换,从而提供更高的准确性和更少的电池消耗。

  2. 对您透明地进行了优化。通过使用位置缓存避免繁重的处理。如果用户有许多位置感知应用程序,那么它不会浪费时间和资源来等待获取新位置和使用以前的位置。

  3. Google Play 服务 3.2 包括对基于位置的服务的多项增强。 Fused Location Provider 现在支持在请求位置更新时选择低功耗模式选项,以及注入(inject)模拟位置的能力——让您能够在各种模拟条件下更有效地测试您的应用程序。 blog

  4. 当希望节省电池电量并使用粗略更新时,FLP 不使用全局定位服务 (GPS),而是使用 WiFi 和手机信号塔信号。

  5. Fused API 提供 3 个位置提供程序。

HIGH_ACCURACY 模式使用所有位置提供者

BALANCED_POWER 模式排除 gps

NO_POWER 模式使用来自其他应用的位置

缺点

  1. 位置管理器,使用 gps,虽然它需要电池,但它在没有网络的情况下也能正常工作。
  2. 室内精度仍然是一个问号,好像你在室内使用应用程序它的精度不是很好。
  3. 位置管理器速度慢但使用 gps 准确,这是准确性和电池消耗之间的权衡。

  4. 如果您计划在 Amazon、F-Droid 或除 Play Store 以外的任何地方发布它,请使用 LocationListener 或实现两者。有不少人不希望谷歌跟踪他们的一举一动

对我来说更准确的是位置管理器,因为它可以在所有平台上使用,不需要 google play 商店。但这需要一些时间,位置检测速度取决于一些因素,例如您是否在空旷的地方,天气等

Related Material

关于Android:在 Android 框架位置 API 上使用 FusedLocationProviderApi 的优缺点是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35572166/

相关文章:

android - 如何解决错误 onClientConnectionState() - status=22 clientIf=7 in BLE

java - 在 Android 应用程序中存储和检索用户数据?

android - 无法登录 Google Play 游戏服务

android - MapFragment 或 MapView getMap() 在 Lollipop 上返回 null

android - 拒绝对先前失败的类com.google.android.gms.location.LocationService进行重新初始化

java - 在 Java 中 run() 方法退出后,线程是否会自动进行垃圾回收?

android - 从异步回调更新 Ionic View

Android蓝牙应用程序进程被杀死

android - 使用 Unity IAP 和新的 Google Play 计费库验证订阅的推荐方法是什么?

java - 自定义布局中 switchpreference 中开/关切换的颜色变化