Created
June 27, 2020 22:27
-
-
Save SirmaXX/c64b2e717e561ee2414350ddeb61fb77 to your computer and use it in GitHub Desktop.
haversin function
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
var R = 6371 //km | |
function sinsqr(x,x1){ | |
difference =(x1-x)*Math.PI/180; | |
result=Math.pow(Math.sin( difference /2) ,2) | |
return result; | |
} | |
function d2tan(a){ | |
result= 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); | |
return result; | |
} | |
/* not işlemler radyan cinsinden olmak zorunda */ | |
function haversine(lat1,long1,lat2,long2){ | |
newlat1=lat1 * Math.PI/180; | |
newlat2= lat2 * Math.PI/180; | |
newsinsqr1=sinsqr(long1,long2); | |
newsinsqr2=sinsqr(lat1,lat2); | |
result=Math.asin( newsinsqr1+newsinsqr2 * newlat1* newlat2); | |
calcd2tan= d2tan(result); | |
finalresult=R * calcd2tan; | |
return finalresult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment