在我的iOS应用程序中,我必须跟踪从起点到当前位置的距离。我实现了这个代码:获取两点之间的距离时遇到问题
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *currentLocation = [locations lastObject];
CLLocation *startLocation = [locations firstObject];
[coordArray addObject:currentLocation];
float speed = currentLocation.speed * 3.6;
if (speed > 0) {
self.labelSpeed.text = [NSString stringWithFormat:@"%.2f Km/h", speed];
[speedArray addObject:[NSNumber numberWithFloat:speed]];
}
CLLocationDistance distance = [startLocation distanceFromLocation:currentLocation];
}
但是,当我尝试使用应用程序它没有得到一个距离。我需要的距离,以显示它的标签,并与距离,我会用这个公式计算步数:
steps = distance/length of human step
我知道这是不准确的,但我不能使用加速度计,因为当iPhone的显示不活跃时它不起作用。有人建议我this solution。为什么我的代码不能给我一个距离?
它在干什么。试图获得距离后,距离的值是多少? currentLocation和startLocation的值是什么?除非你给我们提供有关它在做什么的信息,否则我们无法提供帮助。 “它不工作”不是很具描述性。 – Fogmeister