Created
May 2, 2011 08:46
-
-
Save jnutting/951315 to your computer and use it in GitHub Desktop.
accumulating distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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