Code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
self.currentLocation = newLocation;
BOOL newLocationIsValid = [self isValidLocation:newLocation withOldLocation:oldLocation];
if(newLocationIsValid && oldLocation)
{
int distance = [newLocation distanceFromLocation:oldLocation];
if(distance >2 && distance<10)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance"
message:[NSString stringWithFormat:@"%i meters",distance]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(BOOL)isValidLocation:(CLLocation*)newLocation withOldLocation:(CLLocation*)oldLocation
{
if(newLocation.horizontalAccuracy < 0 )
{
return NO;
}
NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
if(secondsSinceLastPoint < 0)
{
return NO;
}
return YES;
}
This is the main part of my code.
When i run this on my device.
Few initial alerts come with values of distance being around 5 meters. then alerts stop coming
i have set my location manager to desiredFilter of 1.5 meters and kCLLocationAccuracyBest
I just want to consult that are there any loop holes in it because i believe gps is best for it to work and i can't have it on my iPhone i have wifi but i don't know if results are good.so my only hope is someone can say it is correct since i am very much in doubt with my results
But some doubts that i have are that once accuracy is found like 2 to 4 meters. alerts stop showing.
How to manage this. that after every 2 meters movement alerts show up.
basically i want to play a sound whenever iPhone moves 5 ft. but when i start updating location first few alerts come without any change in location of iPhone?how can i filter it that every correct 5 feet movement is registered?
Thanks