次のコードを使用して、デバイスがある場所から別の場所に移動したときの距離を計算しました。正しいかどうか、私のコードを見てください。
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
NSDate *now = [NSDate date];
NSTimeInterval intervalDate = [now timeIntervalSinceDate:now_prev];
sx = acceleration.x * kFilteringFactor + sx * (1.0 - kFilteringFactor);
sy = acceleration.y * kFilteringFactor + sy * (1.0 - kFilteringFactor);
sz = acceleration.z * kFilteringFactor + sz * (1.0 - kFilteringFactor);
[xLabel setText:[NSString stringWithFormat:@"%.2f",sx]];
[yLabel setText:[NSString stringWithFormat:@"%.2f",sy]];
[zLabel setText:[NSString stringWithFormat:@"%.2f",sz]];
float aValue = sqrtf(sx*sx+sy*sy+sz*sz);
[gLabel setText:[NSString stringWithFormat:@"%.2f g",aValue]];
velX += (sx * intervalDate);
distX += (velX * intervalDate);
velY += (sy * intervalDate);
distY += (velY * intervalDate);
velZ += (sz * intervalDate);
distZ += (velZ * intervalDate);
float distance = sqrtf(distX*distX+distY*distY+distZ*distZ);
[distanceLabel setText:[NSString stringWithFormat:@"%.2f",distance*0.0006213f]];
now_prev = [now retain];
}