Created
November 2, 2014 11:35
-
-
Save sabas/967219ce4453c01de4bf to your computer and use it in GitHub Desktop.
Just an implementation of haversine formula in JS
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
function haversine(lat1,lon1,lat2,lon2) | |
{ | |
var R = 6372797.560856; | |
var dlat = (lat2-lat1).toRad(); | |
var dlon = (lon2-lon1).toRad(); | |
var lonh=Math.sin(dlon*0.5); | |
lonh*=lonh; | |
var lath=Math.sin(dlat*0.5); | |
lath*=lath; | |
var tmp= Math.cos(lat1.toRad())*Math.cos(lat2.toRad()); | |
return 2*R*Math.asin(Math.sqrt(lath+tmp*lonh)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment