Measuring velocity via iPhone SDK

后端 未结 5 701

I need to implement a native iPhone app to measure the velocity of the phone (basically a speedometer). I know that you can do so via the CoreLocation API fairly easily, bu

5条回答
  •  無奈伤痛
    2020-12-12 21:52

    The error in the acceleration will accumulate over time. Your best bet is to get an accurate velocity from the GPS, maybe once a minute or less:

    distanceTravelled = sqrt( (position2.x-position1.x)^2 + (position2.y-position1.y)^2 )
    velocity = distanceTravelled/timeBetweenGPSReadings
    

    (where ^2 means squared)

    Then take frequent measurements of the accelerometer:

    newVelocity = oldVelocity + accelerometer*timeBetweenAccelerometerReadings
    

提交回复
热议问题