Edward Sargisson, at Trail Hunger, concludes that Garmin devices do not use the 3d slope distance when reporting distances, but rather the distance at sea level.
Calculation of the Distance Between 2 Points on the Surface of a Great Sphere - the Haversine Formula
This can be achieved using the Haversine Formula, here is a javascript implementation from Movable Type Ltd:
var Bx = Math.cos(φ2) * Math.cos(λ2-λ1); var By = Math.cos(φ2) * Math.sin(λ2-λ1); var φ3 = Math.atan2(Math.sin(φ1) + Math.sin(φ2), Math.sqrt( (Math.cos(φ1)+Bx)*(Math.cos(φ1)+Bx) + By*By ) ); var λ3 = λ1 + Math.atan2(By, Math.cos(φ1) + Bx);
See Also
R. W. Sinnott, "Virtues of the Haversine". Sky and Telescope, vol 68, no 2, 1984