0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sid
  • 17
  • 1
  • 3

1 Answers1

3

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.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • In gees. An acceleration of `1` is approximately equal to the acceleration due to gravity at sea level (see [here](http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAcceleration_Class/Reference/UIAcceleration.html#//apple_ref/doc/c_ref/UIAcceleration)). But why are you asking? You can't use acceleration. – Marcelo Cantos May 27 '10 at 11:17
  • When I say very fast, I mean that the reading would probably be severely degraded within seconds and completely meaningless within minutes; and this is without the problem of not having orientation data, which basically makes it impossible. – Marcelo Cantos May 27 '10 at 11:53
  • Just getting the acceleration accurate is difficult, take a look at [this question](http://stackoverflow.com/questions/2733249/detecting-acceleration-in-a-car-iphone-accelerometer) – progrmr May 27 '10 at 13:07