- 
      
- 
        Save falexandre/03f0a2acf83f21b70091 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | function CalcRadiusDistance(lat1, lon1, lat2, lon2) { | |
| var RADIUSMILES = 3961, | |
| RADIUSKILOMETERS = 6373, | |
| latR1 = this.deg2rad(lat1), | |
| lonR1 = this.deg2rad(lon1), | |
| latR2 = this.deg2rad(lat2), | |
| lonR2 = this.deg2rad(lon2), | |
| latDifference = latR2 - latR1, | |
| lonDifference = lonR2 - lonR1, | |
| a = Math.pow(Math.sin(latDifference / 2), 2) + Math.cos(latR1) * Math.cos(latR2) * Math.pow(Math.sin(lonDifference / 2), 2), | |
| c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), | |
| dm = c * RADIUSMILES, | |
| dk = c * RADIUSKILOMETERS; | |
| this.mi = this.round(dm); | |
| this.km = this.round(dk); | |
| } | |
| CalcRadiusDistance.prototype.deg2rad = function (deg) { | |
| var rad = deg * Math.PI / 180; | |
| return rad; | |
| }; | |
| CalcRadiusDistance.prototype.round = function (x) { | |
| return Math.round(x * 10) / 10; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment