位置提供商真的很耗电吗?

发布于 2024-12-27 21:32:53 字数 347 浏览 4 评论 0原文

我需要实现基于位置的服务。我不需要精确的位置,所以不需要 GPS。

最简单的方法是在应用程序启动时开始侦听位置更新,并将其保留为打开状态:

    mLocationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 100, mPendingIntent);

由于我不需要太多精确度,因此我将最大更新频率设置为 10 秒和 100m,而不是默认的 0、0。

当我们考虑位置时,我们认为电池耗尽,但我想这是一个捷径,只有 GPS 真正耗尽电池。我认为这样使用网络提供商不会耗尽电池。有什么想法吗?

I need to implement location-based service. I don't need fine location, so no GPS is needed.

Easiest would be to start listening for locations updates at app start, and leave it ON:

    mLocationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 100, mPendingIntent);

Since I don't need much accuracy, I set max frequency of updates, to 10s, and 100m instead of default 0, 0.

When we think location, we think battery drain, but I guess this is a shortcut and that only GPS really drains the battery. I think that such a use of network provider wouldn't drain the battery. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2025-01-03 21:32:53

从电池消耗的角度来看,您的 100m 距离过滤器对您几乎没有帮助。这只会控制您的 PendingIntent 由于修复而被执行的次数。

操作系统可能会使用您的 10 秒时间值来控制电源使用,但不能保证。而且,由于价值如此之低,它似乎不太可能被使用。也许每小时一次,但不是每 10 秒一次。

更重要的是,您需要始终保持 CPU 通电。而且,由于您使用的是 requestLocationUpdates()PendingIntent 风格,我猜测您计划收集很长一段时间的数据。

如果您只有 COARSE 权限,Android 希望能够避开 WiFi 热点接近检测,这将节省一些电量。

总体而言,网络提供商比 GPS 提供商消耗更少的电量。 “少”与“少”相差甚远。在 Nexus 级 Android 设备上,GPS + CPU 可为我提供几个小时的电池续航时间(通过使用 Google 导航确定)。我希望网络提供商 + CPU 能够多持续几个小时,但仅此而已,因为 CPU 本身就是相当大的电池消耗。

我更关心的是:

最简单的方法是在应用程序启动时开始侦听位置更新,并将其保留为打开状态

这听起来好像您实际上并不打算删除位置更新。对于任何类型的提供者(除了也许被动提供者)来说,这都是一个非常糟糕的主意。请在注册和删除更新时制定更具体的计划。特别是,请确保用户能够控制何时消耗电池到这种程度。

Your 100m distance filter will do little for you from a battery drain standpoint. That will only control how many times your PendingIntent gets executed due to fixes.

Your 10 second time value might be used by the OS to control power usage, but there is no guarantee. And, with that low of a value, it seems highly unlikely that it would be used. Every hour, maybe, but not every 10 seconds.

The bigger thing is that you will be needing to keep the CPU powered on all the time. And, since you're using the PendingIntent flavor of requestLocationUpdates(), I am guessing that you plan on collecting data for a long time.

If you only have COARSE permission, Android hopefully eschews the WiFi hotspot proximity detection, which will save a bit of power.

On the whole, the network provider will consume less power than will the GPS provider. "Less" is a far cry from "little". On a Nexus-class Android device, GPS + CPU gives me a few hours battery life (as determined by using Google Navigation). I would expect network provider + CPU to last a few hours longer, but that's about it, because the CPU is a fairly significant battery drain in its own right.

My bigger concern is:

Easiest would be to start listening for locations updates at app start, and leave it ON

This sounds like you aren't actually planning on removing your location updates. This is a really bad idea, with any sort of provider (except maybe the passive provider). Please have a more concrete plan for when you are registering and removing the updates. In particular, make sure the user has the ability to control when you are consuming battery to this degree.

汹涌人海 2025-01-03 21:32:53

Android 开发者指南。我建议您查看页面上的代码示例。

这就是他们提到的关于节省电池和各种参数的内容。

调整模型以节省电池和数据交换

当您测试应用程序时,您可能会发现您的模型
提供良好的位置和良好的性能需要进行一些调整。
您可以更改以下一些内容以在两者之间找到良好的平衡
两个。缩小窗口大小

监听位置更新的窗口越小意味着越少
与 GPS 和网络定位服务交互,从而保留
电池寿命。但它也允许更少的地点
选择一个最佳估计。设置位置提供程序以返回更新
不太频繁

降低窗口期间新更新出现的速率可以
还可以提高电池效率,但以牺牲准确性为代价。这
权衡的价值取决于您的应用程序的使用方式。你
可以通过增加参数来降低更新率
requestLocationUpdates() 指定间隔时间和最小值
距离变化。限制一组提供者

取决于您的应用程序的使用环境或
所需的准确度,您可以选择仅使用网络
位置提供商或仅 GPS,而不是两者。仅与交互
其中一项服务可减少电池使用,潜在成本为
准确度。

基本上,请考虑减少您请求更新的频率或请求更新的时间长度。这就像高尔夫一样,你要求的地点越少越好。考虑以下用例:
基于位置的内容标记的示例

在该示例中,应用程序等待,直到用户执行需要位置的操作,然后停止一旦不再需要位置数据就进行轮询。

虽然不断轮询将允许应用程序立即准备好位置,但它根本不值得浪费资源,为了减轻请求位置时的延迟,您可以使用 getLastKnownLocation(字符串提供程序)

编辑:
有一种方法可以确定各种 LocationProvider 的电量使用情况!

调用 getPowerRequirement ()返回三个常量之一

int     POWER_HIGH  A constant indicating a high power requirement.
int     POWER_LOW   A constant indicating a low power requirement.
int     POWER_MEDIUM    A constant indicating a medium power requirement.

为了使您的代码更具可读性,请考虑使用 在任何布尔检查中满足Criteria(条件标准),使您的代码更具可读性。

我将使用它来确定您的应用程序应使用哪种方法来实现最低的电力成本,此外,您还可以受益于支持对提供商有不同电力要求的设备。

There is a topic about this included in the Android Developers Guide. I would recommend that you take a look at the code examples on the page.

This is what they mention regarding conserving battery and various parameters.

Adjusting the model to save battery and data exchange

As you test your application, you might find that your model for
providing good location and good performance needs some adjustment.
Here are some things you might change to find a good balance between
the two. Reduce the size of the window

A smaller window in which you listen for location updates means less
interaction with GPS and network location services, thus, preserving
battery life. But it also allows for fewer locations from which to
choose a best estimate. Set the location providers to return updates
less frequently

Reducing the rate at which new updates appear during the window can
also improve battery efficiency, but at the cost of accuracy. The
value of the trade-off depends on how your application is used. You
can reduce the rate of updates by increasing the parameters in
requestLocationUpdates() that specify the interval time and minimum
distance change. Restrict a set of providers

Depending on the environment where your application is used or the
desired level of accuracy, you might choose to use only the Network
Location Provider or only GPS, instead of both. Interacting with only
one of the services reduces battery usage at a potential cost of
accuracy.

Basically, consider reducing the frequency of the updates you request or the length of time you request them. This is like golf, the less locations you request the better. Consider the following use case:
An example of location based content tagging

In the example the application waits until the user performs an action that needs a location and then stops polling once the location data is no longer needed.

While polling constantly would allow the application to have a location ready at an instant notice its simply not worth the wasted resources, to mitigate the delay when requesting a location you can use getLastKnownLocation (String provider).

Edit:
There is a way to determine power usage for the various LocationProviders!

Calling getPowerRequirement () on a LocationProvider will return one of three constants.

int     POWER_HIGH  A constant indicating a high power requirement.
int     POWER_LOW   A constant indicating a low power requirement.
int     POWER_MEDIUM    A constant indicating a medium power requirement.

To make your code more readable look into using meetsCriteria (Criteria criteria) in any boolean checks to make your code more readable.

I would use this to determine what method your application should use for the lowest power cost, Also you have the benefit of supporting devices that have different power requirements for providers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文