android手机gps定位开发省电要点

android手机gps定位开发省电要点

android手机使用GPS定位会非常费电。google工程师在quora上做了具体的解释,有兴趣可以看看

https://www.quora.com/Battery-Life/Why-does-GPS-use-so-much-more-battery-than-any-other-antenna-or-sensor-in-a-smartphone

GPS is expensive because it is a very slow communication channel—you need to communicate with three or four satellites for an extended duration at50 bits per second. There is no time division as in other communication mechanisms, necessitating powering the antenna for the duration of any communication. Worse, while the GPS is on, the system cannot enter a sleep state. Mobile devices such as Android and the iPhone achieve their battery life largely because they can aggressively and quickly enter into and exit from sleep states.GPS prevents this. GPS's battery draining behavior is most noticeable during the initial acquisition of the satellite's navigation message: the satellite's state, ephemeris, and almanac. Acquiring each satellite takes 12 to 30 seconds, but if the full almanac is needed, this can take up to 12 minutes. During all of this, your phone is unable to enter a deep sleep. A-GPS (Assisted GPS) partially solves this, by sending the navigational message to your mobile device over your cellular data network or even Wi-Fi. As the bandwidth of either of these greatly dwarves the 50bps of the GPS satellites, the time spent powering the GPS antenna or avoiding deep sleep is greatly reduced. Nonetheless, even with A-GPS, using your GPS is a noticeable battery hog. This is again due not to powering the GPS itself, but by preventing the phone from going to sleep. Compounding the cost, most mapping software is processor-intense. A well-designed app can make a significant difference here; Google Maps boasts several optimizations to reduce battery consumption from GPS usage.

1、解决方法就是这个帖子里面讲的,每隔一段时间才监听一次GPS信息。当监听到GPS信息后,关闭GSP,设置一个定时器,等待若干时间后重启GPS。

来源

https://stackoverflow.com/questions/7872863/keeping-a-gps-service-alive-and-optimizing-battery-life

2、及时注销定位监听

在获取到定位之后或者程序处于后台时,注销定位监听,此时监听GPS传感器相当于执行no-op(无操作指令),用户不会有感知但是却耗电。

public void onPause() {

super.onPause();

locationManager.removeListener(locationListener);

}

public void onResume(){

super.onResume();

locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true),6000,100,locationListener);

}

来源http://www.jianshu.com/p/5d83d8649c98

3、设置较长的GPS更新的最短时间,设置最少间隔1秒钟

Android程序调用GPS时,都是直接用函数

public void requestLocationUpdates (long minTime, float minDistance, Criteria criteria, PendingIntent intent) 其中,minTime是间隔多长时间获得一次GPS更新,minDistance是间隔多少距离获得一次GPS更新。

注1:两者都设置时(都不为0),那必须在两个条件同时满足时才通知我们的应用。

注2:由于长期使用GPS模块非常耗电,所有Android建议我们在允许的范围内尽可能地将minTime设置长一些(特别是后台的线程)

注3:当minTime设置不为0(哪怕是1秒),每隔一秒尝试去获取gps数据时都要重新搜星(也就是不会基于上次的定位快速优化并提高精度)。

http://blog.csdn.net/zmpcwl/article/details/10594305

百度地图或者其他地图也是类似的。

4、用Battery Historian分析电池消耗。

为了搞清楚持续监听和间隔监听两种方法的耗电情况,做了一次对比

第一张图是持续监听,调用requestLocationUpdates之后,一直在监听,不停止。可以看到08:58:21到09:10:48这段12分钟时间gps一直在耗电。

第二张图是间隔监听,调用requestLocationUpdates之后,等到获得第一个正确的gps位置之后就调用removeGpsStatusListener停止监听,然后在5分钟之后重新监听。可以看到20:58:21到20:59:00这段时间gps在耗电,然后在后续的5分钟没有gps消耗,在21::04:05开始重新监听,开始了gps消耗,15秒后获得了新的gps地址,又停止监听,gps消耗又没有了。

相关推荐

将“蛐
365bet开户官网

将“蛐"翻译成英文

📅 07-07 👁️ 7416
小程序微商城系统怎么选?主流品牌深度横评,一篇看懂省钱避坑!
8个自制DIY飞机杯教程,比猪肉好用!
365禁用取消提款什么意思

8个自制DIY飞机杯教程,比猪肉好用!

📅 06-28 👁️ 7081
[攻略]【攻略团】T16(凌云)副本攻略
365bet开户官网

[攻略]【攻略团】T16(凌云)副本攻略

📅 08-01 👁️ 3067
二尺八如何换算成厘米,二尺八腰围的裤子是多大
365bet体育备用网站

二尺八如何换算成厘米,二尺八腰围的裤子是多大

📅 07-21 👁️ 9624
高通骁龙685
365禁用取消提款什么意思

高通骁龙685

📅 07-07 👁️ 6157
不小心借了黑网贷怎么办?黑网贷需要还吗?
365bet体育备用网站

不小心借了黑网贷怎么办?黑网贷需要还吗?

📅 07-06 👁️ 4462
小牛信贷多久到账?3分钟了解放款流程与到账时间解析
365bet体育备用网站

小牛信贷多久到账?3分钟了解放款流程与到账时间解析

📅 07-29 👁️ 192
在世界杯现场“胸夹手机”走红!如今再玩新花样,网友玩的真嗨