私の 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のディスプレイがアクティブでない間は動作しないため、加速度計を使用できません。人が私にこの解決策を提案しました。コードで距離が表示されないのはなぜですか?