Change
if ([lastLocation horizontalAccuracy] < 20)...
to
if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))...
According to documentation
A negative value indicates that the location’s latitude and longitude are invalid.
A negative value of horizontalAccuracy
that is.
If you want to set the condition for processing data (seems like you do) you should rewrite the code to:
if (([lastLocation horizontalAccuracy] > 0) && ([lastLocation horizontalAccuracy] < 20))
{
didFindGPS = YES;
//process the data here... since here the location fits your limitations
//and you don't loose the first location (as in original code)
}
else
{
didFindGPS = NO;
}
Note that this code can give you some false alarms for loosing the GPS so you might want to omit the else block.