All pastes #2049325 Raw Edit

Anonymous

public text v1 · immutable
#2049325 ·published 2011-04-22 10:26 UTC
rendered paste body
+ (BOOL) isLocationValid:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
	/* Filter invalid location objects */
	if (!newLocation)
		return FALSE;
	
	/* Filter points with invalid accuracy */
	if (newLocation.horizontalAccuracy < 0)
		return FALSE;
	
	// FIXME: This check on speed shouldn't be performed, according to the SDK documentation
/*#if ! TARGET_IPHONE_SIMULATOR
	// Drop locations having negative speed value (ignore this on the simulator )
	if (newLocation.speed < 0) {
		NSLog(@"Dropped location having speed: %lf", newLocation.speed);
		return FALSE;
	}
#endif*/

#if TARGET_IPHONE_SIMULATOR
	// Checking accuracy when using iphone simulator just to "simulate" the real world

	if (newLocation.horizontalAccuracy > 200) {
		NSLog(@"\nDropped location having accuracy: %lf and speed %lf\n",[newLocation horizontalAccuracy], [newLocation speed]);
		return FALSE;
	}
#endif
	/*
	// Check accuracy value
	if (newLocation.horizontalAccuracy > kMIN_ACCURACY) {
		NSLog(@"\nDropped location having accuracy: %lf and speed %lf\n",[newLocation horizontalAccuracy], [newLocation speed]);
		return FALSE;
	}
	*/

	// Filter unordered points
	if (oldLocation) {
		NSTimeInterval secondsBetweenPoints = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
	
		if (secondsBetweenPoints < 0)
			return FALSE;
	}
	
	NSLog(@"\nAccepted location having accuracy: %lf and speed %lf\n",[newLocation horizontalAccuracy], [newLocation speed]);
		
	return TRUE;	
}