So i’ve been trying to make an arduino based distance measurement device using coordinates from GPS module.

i’ve done a little bit of research and found Haversine formula and several tutorials using tinyGPS++ library function called “distance_between” by Maarten Lamers to do it.

I was wondering if the distance formula used in tinyGPS++library is using Haversine formula or a part of it.

if not which would be more accurate in calculating distance between 2 coordinate ?

thanks

I found the haversine formula in this site Calculate distance and bearing between two Latitude/Longitude points using haversine formula in JavaScript

Here’s the code from the library

```
float TinyGPS::distance_between (float lat1, float long1, float lat2, float long2)
{
// returns distance in meters between two positions, both specified
// as signed decimal-degrees latitude and longitude. Uses great-circle
// distance computation for hypothetical sphere of radius 6372795 meters.
// Because Earth is no exact sphere, rounding errors may be up to 0.5%.
// Courtesy of Maarten Lamers
float delta = radians(long1-long2);
float sdlong = sin(delta);
float cdlong = cos(delta);
lat1 = radians(lat1);
lat2 = radians(lat2);
float slat1 = sin(lat1);
float clat1 = cos(lat1);
float slat2 = sin(lat2);
float clat2 = cos(lat2);
delta = (clat1 * slat2) - (slat1 * clat2 * cdlong);
delta = sq(delta);
delta += sq(clat2 * sdlong);
delta = sqrt(delta);
float denom = (slat1 * slat2) + (clat1 * clat2 * cdlong);
delta = atan2(delta, denom);
return delta * 6372795;
}
```