問(wèn)題描述
我們正在開(kāi)發(fā)一個(gè)使用大量 GPS 的應(yīng)用,我們無(wú)法優(yōu)化電池壽命.
We are developing an app that has heavy GPS usage, and we are unable to optimize the battery life.
即使設(shè)備沒(méi)有移動(dòng),也會(huì)有嚴(yán)重的電池消耗,根據(jù)代碼,這種情況不應(yīng)該發(fā)生.
Even when the device is not moved, there is significant battery drainage that, according to the code, should not happen.
代碼如下:
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = 100;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
理想情況下,我們希望每 20 分鐘觸發(fā)一次 GPS(如果沒(méi)有位置變化,則節(jié)省電池)或每 5 分鐘觸發(fā)一次位置變化.根據(jù)我的開(kāi)發(fā)人員的說(shuō)法,這是無(wú)法做到的
以前我們使用的是 kCLLocationAccuracyBest
,它消耗電池的速度非???,現(xiàn)在我們使用的是 kCLLocationAccuracyHundredMeters
.
Previously we were using kCLLocationAccuracyBest
, which was consuming battery very fast and now we are using kCLLocationAccuracyHundredMeters
.
startUpdatingLocation - 是獲取 GPS 坐標(biāo).還有另一個(gè)調(diào)用 startMonitoringSignificantLocationChanges 來(lái)獲取 AGPS 坐標(biāo),我相信只要蜂窩塔發(fā)生變化就會(huì)返回坐標(biāo),因此會(huì)非??斓叵碾姵?
startUpdatingLocation - is to get the GPS coordinates. There is another call startMonitoringSignificantLocationChanges which is to get AGPS coordinates which I believe returns the coordinates whenever cell tower will change, and hence consumes battery really fast.
distanceFilter - 在生成更新事件之前,設(shè)備必須橫向移動(dòng)的最小距離(以米為單位).根據(jù)距離過(guò)濾器,我們從設(shè)備獲取 GPS 定位,然后將更新后的 GPS 坐標(biāo)發(fā)送到服務(wù)器.
distanceFilter - The minimum distance (measured in meters) a device must move laterally before an update event is generated. On the basis of distance filter we get the GPS fix from the device and then we send the updated GPS coordinates to the server.
我們將不勝感激任何幫助謝謝!
推薦答案
還有另一個(gè)調(diào)用 startMonitoringSignificantLocationChanges是獲取 AGPS 坐標(biāo),我相信它會(huì)返回坐標(biāo)每當(dāng)手機(jī)信號(hào)塔發(fā)生變化時(shí),因此會(huì)真正消耗電池快.
There is another call startMonitoringSignificantLocationChanges which is to get AGPS coordinates which I believe returns the coordinates whenever cell tower will change, and hence consumes battery really fast.
這正是它的作用,但你會(huì)草率地得出關(guān)于所需功率的結(jié)論.GPS 接收器和 WiFi 收發(fā)器可用于幫助確定位置,但它們是額外的設(shè)備,必須通電才能使用.但是像 iPhone 這樣的手機(jī)無(wú)論如何都需要與最近的手機(jī)信號(hào)塔保持聯(lián)系才能接聽(tīng)電話,因此使用手機(jī)信號(hào)塔作為位置信息的來(lái)源在電力方面應(yīng)該是非常有效的.以下是 CLLocationManager 參考頁(yè)談到-startMonitoringSignificantLocationChanges
:
That's exactly what it does, but you're jumping to conclusions about the power required for that. The GPS receiver and WiFi transceiver can be used to help determine location, but they're extra devices that have to be powered to be useful. But mobile phones like the iPhone need to keep in touch with the nearest cell tower anyway in order to receive phone calls, so using cell towers as a source of location information should be very efficient with respect to power. Here's what the CLLocationManager reference page says about -startMonitoringSignificantLocationChanges
:
此接口僅在檢測(cè)到對(duì)設(shè)備的相關(guān)蜂窩塔,導(dǎo)致更新頻率降低并顯著降低功耗.
它還將該服務(wù)描述為提供極大的節(jié)能",因此它似乎是您描述的工作的正確工具.當(dāng)然,如果您還同時(shí)使用標(biāo)準(zhǔn)位置更新機(jī)制,您將看不到節(jié)能效果,因此請(qǐng)確保您沒(méi)有同時(shí)使用這兩種機(jī)制.
It also describes the service as providing "tremendous power savings," so it seems the right tool for the job you describe. Of course, if you're also using the standard location updating mechanism at the same time you won't see that power savings, so make sure you're not using both.
理想情況下,我們希望每 20 分鐘觸發(fā)一次 GPS(如果沒(méi)有位置更改然后節(jié)省電池)或每 5 分鐘(如果有)位置變化.根據(jù)我的開(kāi)發(fā)人員的說(shuō)法,這是無(wú)法做到的
Ideally we want to trigger GPS every 20 minutes (if there is no location change then save battery) OR every 5 minutes if there is location change. According to my developer this cannot be done
這聽(tīng)起來(lái)像是有某種誤解.如果這是您想要的,您當(dāng)然可以每 20 分鐘啟動(dòng)一次 GPS 以進(jìn)行修復(fù),盡管您不能從后臺(tái)執(zhí)行此操作.即使應(yīng)用程序在后臺(tái)運(yùn)行,重要的位置更改服務(wù)也會(huì)通知您的應(yīng)用程序,因此您的開(kāi)發(fā)人員可能正在談?wù)摵笈_(tái)更新.
It sounds like there's some sort of misunderstanding here. You can certainly fire up the GPS every 20 minutes to get a fix if that's what you want, although you can't do that from the background. The significant location change service will notify your app even if it's running in the background, so perhaps your developer is talking about background updates.
這篇關(guān)于iPhone GPS - 電池消耗極快的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!