Calculating the distance between two points

You might want to think about what you’re going to do with the distance once you calculate it, and how big the distance is likely to be. The haversine approach will be more accurate than the example pythagorean code, even over short distances and on parts of the globe where the pythagorean approximation is close to reality, if only because the example pythagorean code is using a 14+ bit cosine table.

As you can see, neither formula cares about altitude. If you care about altitude, you need a different distance measurement altogether. These formulas are approximating the great-circle distance between two points, which is the distance at sea level (as if the earth were a perfectly flat sea-level sphere).

For fans of accuracy overkill, you can also measure distance on a reference ellipsoid (GPS uses the WGS84 ellipsoid). That adds some additional terms to the haversine formula to account for the earth’s polar flattening.