The haversine formula is useful in calculating the distance between two locations on the Earth, when the latitudes & longitudes of the two locations are provided.
An implementation of calcDistance function based on haversine formula in JavaScript is as follows: (the degToRad function is solely a unit converter)
function degToRad(degrees) {
return degrees * Math.PI / 180;
}