Skip to content

How to calculate the speed ? #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LouisJeudy opened this issue Aug 16, 2021 · 1 comment
Open

How to calculate the speed ? #34

LouisJeudy opened this issue Aug 16, 2021 · 1 comment

Comments

@LouisJeudy
Copy link

Hello,

How to calculate the speed (max, in), the average speed ? I can't find any method for.

Thanks in advance

@Luuka
Copy link
Owner

Luuka commented Aug 20, 2021

Hello !

Calculate the speed metadata from the GPXParser object is quite easy. I think it will be part of a future release.

For now you can calculate it from the existing data :
As the speed is just the result of the operation distance/time you can calculate it by yourself for each sub segment (ie. between each GPX points)

  • The time is just the time difference between the two points
  • The distance is the difference between the cumulative distance of the two points

So for each points :

let distance = track.distance.cumul[i+1] - track.distance.cumul[i]; // in meters
let time = track.points[i+1].time - track.points[i].time; // in milliseconds
let speed = distance/time;  //in meters per milliseconds

So you could convert it to km/h by multiplicating by 3600.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants