LatLon.distHaversine=function(L,S,M,T){var K=3956;
var Q=(M-L).toRad();
var N=(T-S).toRad();
L=L.toRad();
M=M.toRad();
var O=Math.sin(Q/2)*Math.sin(Q/2)+Math.cos(L)*Math.cos(M)*Math.sin(N/2)*Math.sin(N/2);
var P=2*Math.atan2(Math.sqrt(O),Math.sqrt(1-O));
var R=K*P;
return R
};
LatLon.distCosineLaw=function(H,K,J,L){var G=3956;
var I=Math.acos(Math.sin(H.toRad())*Math.sin(J.toRad())+Math.cos(H.toRad())*Math.cos(J.toRad())*Math.cos((L-K).toRad()))*G;
return I
};
LatLon.bearing=function(J,L,K,M){J=J.toRad();
K=K.toRad();
var N=(M-L).toRad();
var I=Math.sin(N)*Math.cos(K);
var H=Math.cos(J)*Math.sin(K)-Math.sin(J)*Math.cos(K)*Math.cos(N);
return Math.atan2(I,H).toBrng()
};
LatLon.midPoint=function(J,L,K,M){J=J.toRad();
K=K.toRad();
var N=(M-L).toRad();
var H=Math.cos(K)*Math.cos(N);
var I=Math.cos(K)*Math.sin(N);
lat3=Math.atan2(Math.sin(J)+Math.sin(K),Math.sqrt((Math.cos(J)+H)*(Math.cos(J)+H)+I*I));
lon3=L.toRad()+Math.atan2(I,Math.cos(J)+H);
if(isNaN(lat3)||isNaN(lon3)){return null
}return new LatLon(lat3.toDeg(),lon3.toDeg())
};
LatLon.prototype.destPoint=function(H,I){var N=3956;
var J=this.lat.toRad(),L=this.lon.toRad();
H=H.toRad();
var K=Math.asin(Math.sin(J)*Math.cos(I/N)+Math.cos(J)*Math.sin(I/N)*Math.cos(H));
var M=L+Math.atan2(Math.sin(H)*Math.sin(I/N)*Math.cos(J),Math.cos(I/N)-Math.sin(J)*Math.sin(K));
M=(M+Math.PI)%(2*Math.PI)-Math.PI;
if(isNaN(K)||isNaN(M)){return null
}return new LatLon(K.toDeg(),M.toDeg())
};
LatLon.prototype.finalBrng=function(J,G){var H=this,I=H.destPoint(J,G);
var F=LatLon.bearing(I.lat,I.lon,H.lat,H.lon);
var J=(F+180)%360;
return J
};
LatLon.distRhumb=function(K,Q,L,S){var T=3956;
var O=(L-K).toRad(),N=Math.abs(S-Q).toRad();
var R=Math.log(Math.tan(L.toRad()/2+Math.PI/4)/Math.tan(K.toRad()/2+Math.PI/4));
var M=(Math.abs(O)>1e-10)?O/R:Math.cos(K.toRad());
if(N>Math.PI){N=2*Math.PI-N
}var P=Math.sqrt(O*O+M*M*N*N);
return P*T
};
LatLon.brngRhumb=function(I,K,J,L){var G=(L-K).toRad();
var H=Math.log(Math.tan(J.toRad()/2+Math.PI/4)/Math.tan(I.toRad()/2+Math.PI/4));
if(Math.abs(G)>Math.PI){G=G>0?-(2*Math.PI-G):(2*Math.PI+G)
}return Math.atan2(G,H).toBrng()
};
LatLon.prototype.destPointRhumb=function(U,P){var V=3956;
var R=parseFloat(P)/V;
var L=this.lat.toRad(),S=this.lon.toRad();
U=U.toRad();
var M=L+R*Math.cos(U);
var Q=M-L;
var T=Math.log(Math.tan(M/2+Math.PI/4)/Math.tan(L/2+Math.PI/4));
var N=(Math.abs(Q)>1e-10)?Q/T:Math.cos(L);
var O=R*Math.sin(U)/N;
if(Math.abs(M)>Math.PI/2){M=M>0?Math.PI-M:-Math.PI-M
}lon2=(S+O+Math.PI)%(2*Math.PI)-Math.PI;
if(isNaN(M)||isNaN(lon2)){return null
}return new LatLon(M.toDeg(),lon2.toDeg())
};
function LatLon(C,D){this.lat=C;
this.lon=D
}LatLon.prototype.toString=function(){return this.lat.toLat()+", "+this.lon.toLon()
};
String.prototype.parseDeg=function(){if(!isNaN(this)){return Number(this)
}var H=this.replace(/^-/,"").replace(/[NSEW]/i,"");
var F=H.split(/[^0-9.,]+/);
for(var E in F){if(F[E]==""){F.splice(E,1)
}}switch(F.length){case 3:var G=F[0]/1+F[1]/60+F[2]/3600;
break;
case 2:var G=F[0]/1+F[1]/60;
break;
case 1:if(/[NS]/i.test(this)){H="0"+H
}var G=F[0].slice(0,3)/1+F[0].slice(3,5)/60+F[0].slice(5)/3600;
break;
default:return NaN
}if(/^-/.test(this)||/[WS]/i.test(this)){G=-G
}return G
};
Number.prototype.toRad=function(){return this*Math.PI/180
};
Number.prototype.toDeg=function(){return this*180/Math.PI
};
Number.prototype.toBrng=function(){return(this.toDeg()+360)%360
};
Number.prototype.toDMS=function(){var F=Math.abs(this);
F+=1/7200;
var G=Math.floor(F);
var E=Math.floor((F-G)*60);
var H=Math.floor((F-G-E/60)*3600);
if(G<100){G="0"+G
}if(G<10){G="0"+G
}if(E<10){E="0"+E
}if(H<10){H="0"+H
}return G+"\u00B0"+E+"\u2032"+H+"\u2033"
};
Number.prototype.toLat=function(){return this.toDMS().slice(1)+(this<0?"S":"N")
};
Number.prototype.toLon=function(){return this.toDMS()+(this>0?"E":"W")
};
Number.prototype.toPrecision=function(D){if(this==0){return 0
}var E=Math.ceil(Math.log(this)*Math.LOG10E);
var F=Math.pow(10,D-E);
return Math.round(this*F)/F
};