Maybe but NOT with sampling ‘every 5 seconds.’ and probably not
If you use the Navigate control, the distance you use (what you are trying with your present Blocks) will also fail since ORS servers will not respond within 5 seconds. Even if you could sample this frequently, OpenStreetMap may terminate your app for sampling too often I expect.
Speed? Actual or average? You probably cannot calculate instantaneous speed.
Continue to experiment. You may be able to calculate speed over a sampling interval (location changed event) and save that value then to allow you to determine the speed for the segments and later be able to put them together. In real time, I expect not
As @SteveJG says you can retrieve the “local speed” from the local location sensor and “remote speeds” ( if you need them ) as you retrieve the remote coordinates.
Should be easier an more accurate than calculating from distance/time
If not for the fact that 1 minute of long is equal to one minute of lat only at the Equator, you could be using the Pythagoras. However, as you get away from the Equator minutes of long remain same length (in say, meters or feet) while minutes of latitude get shorter. Hence you must correct the latitudinal difference using the cosine of the latitude.
I am trying to attach a blocks image to help you make your own. This is an actual blocks set from a program that uses gnss positioning data format. So it works. You just use this and adjust according to your case.
! The distance is, of course, expressed in same units (degrees or minutes as per your case) to convert to meters each 1 minute of distance is 1852 meters, give or take some inches. If you use degrees as units then each one degree has 60 minutes.
Yes. Haversines formula always for long distances and the result shows the distance along the ortho. The blocks I pasted are for local distances only - and the result is measured along the loxo.
TLDR the blocks I pasted should never be used for long distances. And beyond about 30 miles a difference will start being noticed between the results of the two formulas.
If you ran the .aia file, you'll notice that the difference will always be 2 seconds, and that's where it captures the coordinates.
The only detail would be:
In the first 2 seconds, you move from point A to point B.
And in the next 2 seconds, you move back from point B to A.
Logically, the coordinates should be the same, but that never happens. I'm speaking from experience testing it.
So there will always be a difference.
That's why I allocated 10 seconds to demonstrate that you're stopped, although I could also test the stop time at a longer time than 2 seconds, but that would be too close.
In OnGnmcReceived you also have speed and timestamp
So if using “locally” ( I mean using the gps of your local phone ) you already have a speed calculated by gps
If this is a a test ( I see in another thread you are showing the position of multiple cars on a map ) and in your final application you have to show position/speed/data of remote vehicles… you not only need the coordinates of the points but also the timestamp ( the exact moment in which these coordinates are recorded, as the one provided in OnGnmcReceived ), in remote communication you generally can’t rely on exact timings…