USING GPS
Converting GPS to Distance
Parallax GPS Module PMB-648
http://www.movable-type.co.uk/scripts/latlong.html
Equirectangular approximationIf performance is an issue and accuracy less important, for small distances Pythagoras’ theorem can be used on an equirectangular projection:*
Formula
x = Δλ.cos(φ)
y = Δφ
d = R.√x² + y²
JavaScript:
var x = (lon2-lon1) * Math.cos((lat1+lat2)/2);
var y = (lat2-lat1);
var d = Math.sqrt(x*x + y*y) * R;
(lat/lon in radians!)This uses just one trig and one sqrt function – as against half-a-dozen trig functions for cos law, and 7 trigs + 2 sqrts for haversine. Accuracy is somewhat complex: along meridians there are no errors, otherwise they depend on distance, bearing, and latitude, but are small enough for many purposes* (and often trivial compared with the spherical approximation itself).
Parallax GPS Module PMB-648
http://www.movable-type.co.uk/scripts/latlong.html
Equirectangular approximationIf performance is an issue and accuracy less important, for small distances Pythagoras’ theorem can be used on an equirectangular projection:*
Formula
x = Δλ.cos(φ)
y = Δφ
d = R.√x² + y²
JavaScript:
var x = (lon2-lon1) * Math.cos((lat1+lat2)/2);
var y = (lat2-lat1);
var d = Math.sqrt(x*x + y*y) * R;
(lat/lon in radians!)This uses just one trig and one sqrt function – as against half-a-dozen trig functions for cos law, and 7 trigs + 2 sqrts for haversine. Accuracy is somewhat complex: along meridians there are no errors, otherwise they depend on distance, bearing, and latitude, but are small enough for many purposes* (and often trivial compared with the spherical approximation itself).