# Haversine Formulas (Or ACOS/COS/SINor SQT) Not functioning with Sensor Location

**URL:** https://community.thunkable.com/t/haversine-formulas-or-acos-cos-sinor-sqt-not-functioning-with-sensor-location/2753592
**Category:** Issues / Bugs
**Tags:** help
**Created:** [December 17, 2023, 9:35pm UTC](https://community.thunkable.com/t/haversine-formulas-or-acos-cos-sinor-sqt-not-functioning-with-sensor-location/2753592 "2023-12-17T21:35:58Z")
**Posts on this page:** 1
**Showing post:** 17

<div class="post-metadata">

### Author: ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)
#### Post date: [December 25, 2023, 10:04am UTC](https://community.thunkable.com/t/haversine-formulas-or-acos-cos-sinor-sqt-not-functioning-with-sensor-location/2753592/17 "2023-12-25T10:04:45Z")

</div>

first of all, the formula is approximate (see wiki [Haversine formula - Wikipedia](https://en.wikipedia.org/wiki/Haversine_formula)) and answer varies depending on where you are on the globe - near the pole or equator - and the proximity of the points you’re measuring.

in your example, if you look at that lat longs for the 2 points,they’re practically adjacent! as if you’re measuring the distance from one corner of your garden to the diagonally opposite corner!  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/1/c1fcb84ef69f0117cb170e17b6a8c92092bed06b.png)

i’ve proved that our thunkable formula works by using this example from [Haversine formula - Rosetta Code](https://rosettacode.org/wiki/Haversine_formula)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/6/365f84dfd3a43c56d5b98dd5460e070ef9d4264a.png)

and i got an answer of 2887.35km (the average answer is 2887.26+ km).

so i know that the formula works.

however your example hovers on an extreme case - the points are so close  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/c/cceeb3267c2574658d51edbd3becd9929e2c3a90.png)

(note: Using 4 decimal places gives a precision of about 11 meters at the equator and about 7 meters at 60 degrees)

after plugging them into into the formula i eventually got these values for variable w and variable v  
w=0.345418744  
v=0.654581256

if you follow the formula we need to compute acos(w+v) - but w+v happens to be 1.00 and acos(1) function means - how many degrees would an angle be such that its cosine is 1? the answer is , according to trigonometry, supposed to be 0 (zero) - ie. cosine of zero is 1.0

somehow (w+v) is not exactly 1.0 and excel stores the values at a higher precision such that w+v is not exactly 1. hence it is able to return a value for acos(w+v) - a value of 1.54516E-05 (which is a very small value, close to zero)

thunkable’s acos is not so precise - it looks like it’s precise only to 5(6?) decimal points and it comes back with a value of 0.000020 (compared to excel’s 0.0000154516)

so i suggest,you apply this formula only to points that are greater than 1 degree each way - by lat or by long.

the formula works very well for computing distances (approximate) between 2 points that are not adjacent.

---

_[View the full topic](https://community.thunkable.com/t/haversine-formulas-or-acos-cos-sinor-sqt-not-functioning-with-sensor-location/2753592)._
