Reputation: 181
I'm trying to obtain the current distance that has been travelled since LocationManager was started. But i'm facing a few issues.
here is the code I have so far:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if (self.startLocation == nil)
{
totalDistanceBetween = 0;
_startLocation = newLocation;
}
CLLocationDistance distanceBetween = [newLocation distanceFromLocation:_startLocation ];
self.startLocation = newLocation;
totalDistanceBetween += distanceBetween;
NSString *cycleDistanceString = [[NSString alloc]
initWithFormat:@"%f",
totalDistanceBetween];
_CurrentDistance.text = cycleDistanceString;
}
@end
When I run my app my label CurrentDistance is not updated at all. I'm still relatively new to objective-c so not sure where I'm going wrong any ideas?
Thanks
Upvotes: 0
Views: 46
Reputation: 119031
You should add a log or debug to ensure you are receiving location callbacks. If not, you haven't registered for updates (properly).
If you are getting callbacks then I guess _CurrentDistance
is an outlet to a label which isn't connected (so you are asking nil
to do something and nothing happens).
Upvotes: 2