Skip to content

Instantly share code, notes, and snippets.

@fmundaca
Created February 20, 2013 17:05
Show Gist options
  • Save fmundaca/4997124 to your computer and use it in GitHub Desktop.
Save fmundaca/4997124 to your computer and use it in GitHub Desktop.
- (BOOL)isValidLocation:(CLLocation *)newLocation
withOldLocation:(CLLocation *)oldLocation
{
// Filter out nil locations
if (!newLocation)
{
NSLog(@"No es valido newLocation is Nil");
return NO;
}
// Filter out points by invalid accuracy
if (newLocation.horizontalAccuracy < 0)
{
NSLog(@"No es valido horizontalAccuracy < 0");
return NO;
}
// Filter out points that are out of order
NSTimeInterval secondsSinceLastPoint =
[newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
if (secondsSinceLastPoint < 0)
{
NSLog(@"No es valido secondsSinceLastPoint = %f ",secondsSinceLastPoint);
return NO;
}
// Filter out points created before the manager was initialized
NSTimeInterval secondsSinceManagerStarted =
[newLocation.timestamp timeIntervalSinceDate:startTime];
if (secondsSinceManagerStarted < 0)
{
NSLog(@"No es valido secondsSinceManagerStarted < 0 => %f",secondsSinceManagerStarted);
return NO;
}
NSLog(@"ES VALIDO");
// The newLocation is good to use
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment