Question

How can I use the UIAccelerometer class to compute the distance traveled by a person?

Was it helpful?

Solution

This is impractical, due to limitations with accelerometers.

  1. They measure acceleration, not distance. You can integrate it to get the velocity and integrate the velocity to get a distance, but the double integration will lose accuracy very fast, and even without the accuracy concerns, you need to establish an initial velocity, which the accelerometer can't work out.
  2. You also need high-frequency orientation data to distinguish between acceleration and gravity. Without this, you can't tell in which direction the velocity is increasing. You can't even tell if it is linear; someone could be spinning the device on the end of a string.

Use GPS instead, via the CLLocationManager class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top