这是我在 viewDidLoad
:
_locationManager = [[CLLocationManager alloc] init];
[_locationManager setDelegate:self];
if ([[UIDevice currentDevice].systemVersion hasPrefix:@"8"]) {
[_locationManager requestAlwaysAuthorization];
}
[_locationManager startMonitoringSignificantLocationChanges];
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[_locationManager setDistanceFilter:50];
[_locationManager startUpdatingLocation];
[_locationManager startUpdatingHeading];
这就是我的didUpdateLocations
方法的样子:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation* newLocation = [locations lastObject];
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 50.0 && newLocation.horizontalAccuracy > 0) {
// If the event is recent, do something with it.
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
}
问题是蓝色当前位置点不准确地移动并且不会保持静止。当我静止不动时我会观察到这种行为。我正在尝试过滤 didUpdatelocations
方法中的位置,但我不知道为什么它不起作用。请指导我如何过滤它。或者你认为这种错误的行为是因为别的什么?
答案 0 :(得分:0)
您是否尝试过减少setDistanceFilter:50
?根据框架参考,这意味着该位置仅在设备移动50米后才更新。默认值为kCLDistanceFilterNone
,以通知所有动作。