Iphone 正在停止CLLocationManager?
我想询问关于停止CLLocationManager-startUpdatingLocation的建议。目前我正在考虑两种方法,但我不确定使用哪种方法,我想了解其他人是如何做到这一点的: 方法\u 001:Iphone 正在停止CLLocationManager?,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我想询问关于停止CLLocationManager-startUpdatingLocation的建议。目前我正在考虑两种方法,但我不确定使用哪种方法,我想了解其他人是如何做到这一点的: 方法\u 001: [locationManager startUpdatingLocation]; [self performSelector:@selector(stopUpdatingLocation:) withObject:@"TimedOut" afterDelay:30]; [locationMa
[locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocation:) withObject:@"TimedOut" afterDelay:30];
[locationManager startUpdatingLocation];
- 由于总是运行30秒,可能会浪费电池寿命
- 如果网络速度慢,可能无法及时获得准确的位置
- 感觉这是一种很好的实现超时的方法
[locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocation:) withObject:@"TimedOut" afterDelay:30];
[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次(或更少)尝试中可能无法解析准确位置
- 4可能不会返回CLLocationManager的结果,并且我们从不超时
- 更好的电池寿命,因为我们立即停止对一个良好的结果
只是好奇?不确定您到底想做什么,但我认为CLLocationManager会在内部处理这些情况。只需将其配置为:
locManager.desiredAccuracy = 2000.0f; // 2 kilometers - hope for accuracy within 2 km.
locManager.distanceFilter = 1000.0f; // one kilometer - move this far to get another update
然后在回调didUpdateToLocation:fromLocation:
如果你有一个积极的信号位
[locManager stopUpdatingLocation]; // stop GPS
编辑:添加符号位
if (signbit(newLocation.horizontalAccuracy)) {
// Negative accuracy means an invalid or unavailable measurement, so punt.
} else {
// this is a usable measurement.
}
嗯,我想我更喜欢第一个。我不知道是否可以确定调用
didUdpateToLocation:
方法的频率。我认为暂停时间更可靠。为什么不将两种方法结合起来,给出第三种方法(我认为最佳结果在一定时间内没有改善)
我写了一份GIT回购协议,你可以免费使用
- 如果结果的准确度优于可接受的准确度,我们就完蛋了
- 如果我们得到一个关于神秘性的更新,我们会等待MaximumWaitTimeorBetterResult来得到一个更好的结果,-如果这没有发生,我们就完成了,并选择最好的一个
- 如果我们不断得到更新,超过最大尝试次数,我们会选择最好的一个(可能我们正在移动)
- 如果我们在30秒内没有得到任何其他更新,我们就完成了(可能不会有任何其他更新)
这就是我所想的,目前我正在使用方法_002,但注意到有时没有第四次呼叫代表。如果第一次申报特别准确,这种情况似乎就会发生。同样,如果将3设置为超时,则特别困难的情况(坏的单元格覆盖率)无法准确解析到可用位置。CLLocationManager是否响应选择器“disable”?@atreat-good catch-这是我代码中的自定义包装方法。我已更新以使用正确的方法调用。您所说的“如果您有正符号位”是什么意思?是否有人有任何证据表明CLLocationManager可以以负水平精度返回CLLocation?horizontalAccuracy的文档说明:“负值表示纬度和经度无效。”因此CLLocationManager不应返回具有这种精度的CLLocation,因为它不应返回具有无效纬度或经度的CLLocation。。。思想?