Determining the speed of a vehicle using GPS in android

后端 未结 4 1744
轻奢々
轻奢々 2020-12-07 09:18

I would like to know how to get the speed of a vehicle using your phone while seated in the vehicle using gps. I have read that the accelerometer is not very accurate. Anoth

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 09:55

    GPS works fine in a vehicle. The NETWORK_PROVIDER setting might not be accurate enough to get a reliable speed, and the locations from the NETWORK_PROVIDER may not even contain a speed. You can check that with location.hasSpeed() (location.getSpeed() will always return 0).

    If you find that location.getSpeed() isn't accurate enough, or it is unstable (i.e. fluctuates drastically) then you can calculate speed yourself by taking the average distance between a few GPS locations and divide by the time elapsed.

提交回复
热议问题