我想征求关于停止CLLocationManager -startUpdatingLocation的建议。目前,我正在考虑两种方法,但我不确定使用哪种方法,并想知道其他人是如何做到这一点的:
Method_001:
[locationManager startUpdatingLocation];
[self performSelector:@selector(stopUpdatingLocation:) withObject:@"TimedOut" afterDelay: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次(或更少)的尝试中,timeout.
只是好奇?
发布于 2011-03-30 18:25:17
嗯,我想我更喜欢第一个。我不知道我们是否能够确定didUdpateToLocation:方法被调用的频率。我认为暂停时间更可靠。
发布于 2011-03-30 17:40:02
不确定您到底想做什么,但我认为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然后在回调
[locManager stopUpdatingLocation]; // stop GPS编辑:添加小数
if (signbit(newLocation.horizontalAccuracy)) {
// Negative accuracy means an invalid or unavailable measurement, so punt.
} else {
// this is a usable measurement.
}发布于 2014-01-27 17:18:09
为什么不把这两种方法结合起来,并给出第三种(我最好的结果并没有在一定的时间内改善)
我在这上面写了一个GIT,您可以自由使用https://github.com/xelvenone/M6GPSLocationManager。
如果结果的准确性比
F 210
代码
- (void)scopeToCurrentLocationWithAcceptableAccuracy:(CLLocationAccuracy)acceptableAccuracy
maximumWaitTimeForBetterResult:(NSTimeInterval)maximumWaitTimeForBetterResult
maximumAttempts:(NSInteger)maximumAttempts
onCompletion:(M6GPSLocationManagerCompletion)completion;https://stackoverflow.com/questions/5489662
复制相似问题