Distance traveled to determine speed

This time I need to know the vehicle's speed on the route, but using the vehicle's coordinates. That is, the start and end points.

I want to do this without needing to click on the screen. This means I will use a timer.

This reading will be taken every 5 seconds.

Is this possible?

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

Speed using the native LocationSensor: A Basic LocationSensor Speedometer

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

I've been researching how to calculate distance in kilometers linearly using coordinates, mathematically.

And I think this could work to obtain the distance.

And with this distance, obtain the speed. If I reduce the time capture, it would be more accurate.

If I could solve this formula...

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.

Or

1 Like

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.

TIMAI2


I've taken one of your examples, "Seeking Precision."

After so many tests where:

I took the coordinates between two points every two seconds (to calculate the distance in kilometers).

And every two seconds I obtained the speed.

And if the coordinates are the same for more than 10 seconds, it means the vehicle is stopped.

I'd like opinions or any suggestions for improvement.

Speed.aia (19.9 KB)

In the speed=distance/time formula you are using a constant time of 2 seconds: are you sure this time remain constant?

It's the first digit of the seconds on the clock, from 0 to 9. It shouldn't fail while it's active. What do you think could go wrong?

Yes, of course, if there's even a slight difference in those 2 seconds of reading, it's because the device is changing position and moving.

There's always room for improvement, especially with the speedometer, for example:

It will always display a constant number of 1.8 km/h.

Another improvement would be to reduce the number of blocks by assigning reading pauses, like this 2-second example.

The same applies to the stop readings, which are 10 seconds.

In the formula speed=distance/time

  • distance is distance between two points ( lets say P2-P1 ) you already calculated
  • time is the two points recording time difference ( lets say T2-T1 )

Are you sure this time difference is always 2 seconds?

If you are retrieving these two points from one or more “remote nodes” I wouldn’t be so sure about timings


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.

What do you propose?

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…

1 Like

Yes, I've noticed it, but I don't have examples to create the blocks. Also, it's unknown how often the readings are taken.

If you have any examples, I would appreciate it.

By the way, I did this to also obtain data from other vehicles by varying the frequency. I also can't accumulate that much data every two seconds.

In the attached example I’m reading lat,lon and timestamp from gps ( but you can enable also reading of speed directly from gps )

Speed03.aia (19.1 KB)