I downloaded the Garmin golf data from Garmin Connect to do some additional analysis. Specifically, I used the shot data from Golf-SHOT.json).
I tried both the Haversine and Vincenty formulas, using the "startLoc" "lat" and "lon" and "endLoc" "lat" and "lon", to generate the shot distance. In each case, I get a different result than is provided by "meters".
What formula is being used by Garmin?
Below is the shot data used.
{
"id": 8356171700,
"scorecardId": 303276191,
"playerProfileId": 69671545,
"shotTime": 1736099276000,
"shotOrder": 1,
"shotTimeZoneOffset": -28800000,
"clubId": 36422030,
"holeNumber": 1,
"autoShotType": "USED",
"startLoc": {
"lat": 444494771,
"lon": -1455239696,
"lie": "TeeBox",
"lieSource": "CARTOGRAPHY"
},
"endLoc": {
"lat": 444515193,
"lon": -1455224042,
"lie": "Fairway",
"lieSource": "CARTOGRAPHY"
},
"meters": 223.214,
"shotSource": "DEVICE_AUTO",
"shotType": "TEE",
"lastModifiedTime": "2025-01-05T21:54:50Z"
}
And the code
import math
def vincenty(lat1, lon1, lat2, lon2):
# Convert latitude and longitude to radians
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])
# Calculate the difference between the two coordinates
dlat = lat2 - lat1
dlon = lon2 - lon1
# Apply the Vincenty formula
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
# Calculate the ellipsoid parameters
f = 1/298.257223563 # flattening of the Earth's ellipsoid
b = (1 - f) * 6356.7523142 # semi-minor axis of the Earth's ellipsoid
# Return the distance
return c * b
def haversine(lat1, lon1, lat2, lon2):
# Convert latitude and longitude to radians
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])
# Calculate the difference between the two coordinates
dlat = lat2 - lat1
dlon = lon2 - lon1
# Apply the haversine formula
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.asin(math.sqrt(a))
# Calculate the radius of the Earth
r = 6371 # radius of Earth in kilometers
# Return the distance
return c * r
print("haversine", haversine(44.4494771, -145.5239696, 44.4515193, -145.5224042))
print("vincenty", vincenty(44.4494771, -145.5239696, 44.4515193, -145.5224042))
// RESULT IN KILOMETERS: haversine 0.25885547384607
// RESULT IN KILOMETERS: vincenty 0.2574106339786147
// RESULT IN KILOMETERS: vincenty 0.2574106339786147