我想问一下关于停止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