How can I use the UIAccelerometer
class to compute th开发者_JAVA百科e distance traveled by a person?
This is impractical, due to limitations with accelerometers.
- 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.
- 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.
精彩评论