Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the velocity of an Android device?

Tags:

android

What is the easiest way to find out how fast the Android device is traveling?

Also, is there a way to register an intent for speed? Example: intent if the device goes more than 20 miles an hour.

like image 913
Cory Avatar asked Apr 27 '10 18:04

Cory


2 Answers

The easiest way is to get the speed of the device is from the GPS, more specifically the time it takes to travel between 2 points. Luckily this is already done for you with the Location class: Location.getSpeed() which returns a float with the speed in m/s.

See the Android developer reference for more info

like image 68
James Goodwin Avatar answered Nov 20 '22 08:11

James Goodwin


you can calculate speed precisely by multiplying acceleration to time it was applied for. this method is very sensitive so you will have to add some border check to filter shakes.

like image 39
Andrey Avatar answered Nov 20 '22 10:11

Andrey