Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Created June 27, 2020 22:27
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 SirmaXX/c64b2e717e561ee2414350ddeb61fb77 to your computer and use it in GitHub Desktop.
Save SirmaXX/c64b2e717e561ee2414350ddeb61fb77 to your computer and use it in GitHub Desktop.
haversin function
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