Created
February 7, 2014 20:53
-
-
Save robwilkerson/8871634 to your computer and use it in GitHub Desktop.
Computes the distance in miles between two sets of coordinates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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