Skip to content

Instantly share code, notes, and snippets.

@jnutting
Created May 2, 2011 08:46
Show Gist options
  • Save jnutting/951315 to your computer and use it in GitHub Desktop.
Save jnutting/951315 to your computer and use it in GitHub Desktop.
accumulating distance
// The Core Location example in Beginning iPhone 4 Development shows how to
// calculate a distance from a starting point, but it doesn't show how far you've
// actually traveled. These changes should let you see an accumulated distance.
// Add this to the interface declaration in WhereAmIViewController.h:
CLLocationDistance totalDistance;
// then replace the last chunk of locationManager:didUpdateToLocation:fromLocation:
// with this:
CLLocationDistance distance = [newLocation distanceFromLocation:startingPoint];
totalDistance += distance;
NSString *distanceString = [[NSString alloc] initWithFormat:@"%gm", totalDistance];
distanceTraveledLabel.text = distanceString;
[distanceString release];
self.startingPoint = newLocation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment