after a lot of research, I myself answer this question.
#define kDistanceFilter 5
#define kRotationFilter 60
-(void)initInfluenceWalkingTest{
wasRotation = NO;
if (!self.locationManager) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.distanceFilter = kDistanceFilter;
self.locationManager.headingFilter = kRotationFilter;
[self.locationManager startUpdatingLocation];
}
if ([CLLocationManager headingAvailable]) {
[self.locationManager startUpdatingHeading];
}
if (!self.location) {
self.location = [[CLLocation alloc] init];
}
self.locations = [NSMutableArray array];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *location = (CLLocation*)locations.lastObject;
NSTimeInterval locationAge = -[location.timestamp timeIntervalSinceNow];
if (locationAge > 5.0){
return;
}
if (location.horizontalAccuracy < 0)
return;
if (location.horizontalAccuracy>kDistanceFilter-1 && self.location.horizontalAccuracy<=kDistanceFilter) {
[self.locations addObject:location];
}
self.location = location;
self.buttonTap.hidden = (self.location.speed>0);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
if (newHeading.headingAccuracy < 0)
return;
CLLocationDirection direction = ((newHeading.trueHeading > 0) ?
newHeading.trueHeading : newHeading.magneticHeading);
if (self.direction>0 && ABS(self.direction - direction)>kRotationFilter) {
wasRotation = YES;
}
self.direction = direction;
}
April source
share