It is normal to initially get a cached location from before. You can ignore older cached data by looking at the timestamp of the CLLocation.
You are printing the accuracy incorrectly, use %f not %d, type is double not int.
Location can change quickly when GPS first starts because you have a low accuracy location from cell triangulation, then as you get GPS acquisition you get a higher accuracy location. Those can be far apart (1000m) and it appears that you moved far in a few seconds but only the accuracy has changed.
Don't use two locations that have very different accuracy for computing distance traveled.
EDIT Added code sample, how to ignore old location data. You decide how old to ignore, I used 60 seconds here:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSTimeInterval ageInSeconds = -[newLocation.timestamp timeIntervalSinceNow];
if (ageInSeconds > 60.0) return; // data is too long ago, don't use it
// process newLocation
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…