我正在尝试获取自LocationManager启动以来已经过的当前距离。但我面临一些问题。
这是我到目前为止的代码:
-(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
当我运行我的应用程序时,我的标签CurrentDistance根本没有更新。我还是比较新的目标-c所以不确定我哪里出错任何想法?
由于
答案 0 :(得分:2)
您应该添加日志或调试以确保您接收位置回调。如果没有,您还没有注册更新(正确)。
如果你收到回调,那么我猜_CurrentDistance
是一个没有连接的标签的出口(所以你要求nil
做某事而没有任何反应。)