The haversine formula works correctly when I hardcode the latitude and longitude, but when I try to get them from the location sensor, my output is always 0.
What are the values of app variable last_lat
and app variable last_lon
right before you call the function to calculate the distance? What are the values of the green latitude
and longitude
blocks after calling the GetCurrentLocation
function?
You can display them in a text inputโs text (to be able to copy them) or a labelโs text. I would get those values and try all four manually in the formula1 function to see if that works.
The values for the first interaction, after walk 10 seconds, are:
last_lat = 42.99577312547992
last_lon = -71.4658010937939
longitude = -71.46576614125767
latitude = 42.99580510244052
Here is my app:
https://x.thunkable.com/copy/dd5263e2ccc64debb45a9bfdde491502
Your first screenshot shows weird code patterns. Iโm assuming that all your blocks belong in the โthen doโ section unless they are truly unrelated to the blocks that come before them.
Yes, all of the code is inside the โthen doโ
Your โdโ value in the formula1 function is returning zero. Iโm not sure why but you need to fix that equation. Iโd suggest starting from scratch with that line of code (not the whole formula, just the calculation for โdโ).
Iโd also base your equations off of the screenshot in this post (Calculate distance travelled - #2 by manyone
Little changes youโve made such as multiplying app variable d
by a constant later instead of as part of the calculation of app variable d
can have impacts that you donโt expect.
Also a note that Iโve used the Haversine formula to calculate relatively large distances like 0.5 miles but Iโve never used it for distances of just a few feet. I donโt know if itโs accurate at such small scale.
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
Need help? How to Ask Great Questions Debugging A Project API JSON Tutorial
Want to hire a Certified Thunkable Expert? Elevate your app with Tatiang on Fiverr
last_lat = 42.99577312547992
last_lon = -71.4658010937939
longitude = -71.46576614125767
latitude = 42.99580510244052
[/quote]
i asked Bing to calculate the distance between these 2 points and it came back with this:
the answer is about 4.5 meters - and thatโs using high precision trigonometric routines.
i think you;re getting zero because the trigonomoetric routines being used by thunkable have a low precision such that the sin of a very small angle is rounded to zero. if you examine the formula, youโll end up computing the sin (squared) of a verrry small delta change between two angles.
i think you cannot rely on this formula on points that are very close!
I tried the same way on the post ( (Calculate distance traveled - #2 by manyone )
I still get 0 for my โdโ calculation because some of (w + v) are close to 1, and asin(1) is 0. Do you think it is possible to calculate the distance while Iโm walking in thunkable?
I donโt recommend it.
But you should put it to a test. Surely your waking exercise is more than 4 meters or 10 feet. Also bring one of thise step counters tto verify. Please let us know your results.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.