## 2014년 12월 6일 토요일

### current speed

How can I read, extract or calculating the current speed from location sensor?
I need the value in km/h.
Can anyone help me?

--
One way to calculate speed is to compare two location readings, the most recent and one prior. When those readings are taken, record the time. Calculate the distance between Location1 and Location2 using the Haversine algorithm (search for it, there are plenty of references on the Web).  Haversine will calculate straight-line distance between two points.   You now have two times and a distance.

If you convert the Haversine distance to kilometers   and the difference in time between Location1 and Location2 to hours, you got it!     The Clock component measures time in ms.  1000 ms = 1 second; 60 seconds = 1 minute; 60 minutes = 1 hour.

Does that help?   The most difficult parts are writing a block version of Haversine and saving the Location1 data and Location2 data.   Try some blocks.   If you run into difficulty, post a screen capture (jpg or png prefered please) and ask a specific question and you will get advice.

--
I need the current speed anytime, but not the average speed between two points.
Thank you anyway Steve!

--
there is no block available for current speed, you have to calculate it yourself as SteveJG suggested

--
You can get the instantaneous speed using Android Studio ....  http://developer.android.com/guide/topics/location/strategies.html

AI2 does not have this capability, but if you use Android Studio call you can use `getSpeed()` in your location listener, in the onLocationChanged() callback

Is it possible using the Accelerometer?  Conceptually, possibly but the accuracy would be terrible I imagine and you would have to account for all three axes.   The orientation of the device would be an issues, the accuracy of the accelerometer itself,  the math for correcting for the velocity vectors in x,y,z perhaps.

If you must have the instantaneous velocity try Android Studio,  this Java based professional compiler has the tools you need, AI2 does not have a getSpeed function.  And, then after you get getSpeed, how accurate is that value going to be?   Try it and find out.

--
All these things are very complex for me!
In the first i was thinking if I can calculate the current speed with the distance interval and time interval and some maths!
But ok! it doesn't matter!
I'm gone on try another way to do my job!
Thank you very much for your time

--