Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
Created February 7, 2014 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwilkerson/8871634 to your computer and use it in GitHub Desktop.
Save robwilkerson/8871634 to your computer and use it in GitHub Desktop.
Computes the distance in miles between two sets of coordinates.
/**
* Computes the distance in miles between two sets of coordinates.
*
* @param object from object containing longitude and latitude members
* @param object to object containing longitude and latitude members
* @return number
*/
Inova.Models.Location.distance = function(from, to) {
// approx. dist in miles, nothern hemisphere
// http://www.meridianworlddata.com/Distance-Calculation.asp
try {
return Math.sqrt(Math.pow(69.1 * (to.latitude - from.latitude ), 2) + Math.pow(53 * (to.longitude - from.longitude ), 2)).toFixed(1);
} catch( e ) {
throw (e );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment