How to fix total distance and pace

Hi, so this is my running app.

But distance and pace is not working, i tried everything but nothing helps. Can someone give me advice what to change? Thanks

It’s pretty complicated to try and figure out all of those blocks. It would help if you posted the source of your equations and explained how you’re attempting to determine distance and pace.

So basically, in this setup, I’m using a timer to update the distance, pace, and route every 5 seconds. Then I check the user’s speed from the location data. If the speed is greater than zero, it means the user is moving, so the app calculates the distance, updates the total, draws the path, and saves the new location. If not, it skips those steps.

The problem is, I’m not sure how to use the map component’s polyline correctly. Right now, it’s not drawing the line. Also, the distance and pace aren’t updating, and they stay at zero even when I’m testing it and moving.

I’m calculating the distance with the Haversine formula, passing the initial latitude and longitude along with the current latitude and longitude. It should return the distance and then add it to the variable, but that’s not working. As for pace, I’m dividing the total minutes (I have this value in my stopwatch timer) by the total distance, but it’s not showing anything. I guess the problem is with the total distance variable, but I don’t know where it’s failing.

1 Like

Would you mind sharing the project link? I can probably troubleshoot it quicker if I can test it on my device versus looking through the code blocks without previewing it.

or this one, i am not sure which one will work

Your formulas for calculating x, y, and z are significantly different from what I’ve always used which is based off of various websites that mention D, V, and W. So what’s worked for me is this:

(Source: this topic)

But maybe part of the issue you’re having is that the level of precision calculated may not be enough to register for small movements. See Haversine Formulas (Or ACOS/COS/SINor SQT) Not functioning with Sensor Location - #17 by manyone.