我想問一下關於停止CLLocationManager -startUpdatingLocation的建議。目前,我正在考慮兩種方法,但我不能確定使用哪一個,並希望得到一個想法其他人是如何做到這一點:停止CLLocationManager?
Method_001:
[locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocation:) withObject:@"TimedOut" afterDelay:30];
- 潛在浪費電池壽命一如既往運行30秒
- 如果網絡速度較慢可能無法及時獲得準確位置
- 感覺實現超時的方法非常簡單。
Method_002:
[locationManager startUpdatingLocation];
然後內:-locationManager:didUpdateToLocation:fromLocation:
添加:
static int timeOut = 0;
timeOut++;
// Other code that checks for and stops
// when a suitable result, accuracy, age etc is found.
if(timeOut >= 4) {
[[self locationManager] stopUpdatingLocation];
timeOut = 0;
return;
}
- 可能無法在4(或更小)的嘗試解決準確位置。
- 對於CLLocationManager,可能不會返回4個結果,我們從不超時。
- 更好的電池壽命,因爲我們立即停止一個好的結果。
只是好奇嗎?
這就是我在想什麼,目前我正在使用method_002,但注意到有時沒有第四次調用委託。這似乎發生在第一次回報特別準確的情況下。同樣,如果將3設置爲超時,則特別困難的情況(小區覆蓋不良)不能準確解析到可用位置。 – fuzzygoat 2011-03-30 18:48:18