function LatLon(b,c,a){if(typeof a=="undefined"){a=6371}this._lat=b;this._lon=c;this._radius=a}LatLon.prototype.distanceTo=function(p,h){if(typeof h=="undefined"){h=4}var g=this._radius;var f=this._lat.toRad(),j=this._lon.toRad();var e=p._lat.toRad(),i=p._lon.toRad();var m=e-f;var b=i-j;var o=Math.sin(m/2)*Math.sin(m/2)+Math.cos(f)*Math.cos(e)*Math.sin(b/2)*Math.sin(b/2);var n=2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o));var k=g*n;return k.toPrecisionFixed(h)};LatLon.prototype.bearingTo=function(b){var f=this._lat.toRad(),e=b._lat.toRad();var c=(b._lon-this._lon).toRad();var g=Math.sin(c)*Math.cos(e);var a=Math.cos(f)*Math.sin(e)-Math.sin(f)*Math.cos(e)*Math.cos(c);var d=Math.atan2(g,a);return(d.toDeg()+360)%360};LatLon.prototype.finalBearingTo=function(b){var f=b._lat.toRad(),e=this._lat.toRad();var c=(this._lon-b._lon).toRad();var g=Math.sin(c)*Math.cos(e);var a=Math.cos(f)*Math.sin(e)-Math.sin(f)*Math.cos(e)*Math.cos(c);var d=Math.atan2(g,a);return(d.toDeg()+180)%360};LatLon.prototype.midpointTo=function(b){lat1=this._lat.toRad(),lon1=this._lon.toRad();lat2=b._lat.toRad();var c=(b._lon-this._lon).toRad();var a=Math.cos(lat2)*Math.cos(c);var d=Math.cos(lat2)*Math.sin(c);lat3=Math.atan2(Math.sin(lat1)+Math.sin(lat2),Math.sqrt((Math.cos(lat1)+a)*(Math.cos(lat1)+a)+d*d));lon3=lon1+Math.atan2(d,Math.cos(lat1)+a);return new LatLon(lat3.toDeg(),lon3.toDeg())};LatLon.prototype.destinationPoint=function(a,f){f=f/this._radius;a=a.toRad();var e=this._lat.toRad(),c=this._lon.toRad();var d=Math.asin(Math.sin(e)*Math.cos(f)+Math.cos(e)*Math.sin(f)*Math.cos(a));var b=c+Math.atan2(Math.sin(a)*Math.sin(f)*Math.cos(e),Math.cos(f)-Math.sin(e)*Math.sin(d));b=(b+3*Math.PI)%(2*Math.PI)-Math.PI;if(isNaN(d)||isNaN(b)){return null}return new LatLon(d.toDeg(),b.toDeg())};LatLon.intersection=function(d,b,c,a){lat1=d._lat.toRad(),lon1=d._lon.toRad();lat2=c._lat.toRad(),lon2=c._lon.toRad();brng13=b.toRad(),brng23=a.toRad();dLat=lat2-lat1,dLon=lon2-lon1;dist12=2*Math.asin(Math.sqrt(Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(lat1)*Math.cos(lat2)*Math.sin(dLon/2)*Math.sin(dLon/2)));if(dist12==0){return null}brngA=Math.acos((Math.sin(lat2)-Math.sin(lat1)*Math.cos(dist12))/(Math.sin(dist12)*Math.cos(lat1)));if(isNaN(brngA)){brngA=0}brngB=Math.acos((Math.sin(lat1)-Math.sin(lat2)*Math.cos(dist12))/(Math.sin(dist12)*Math.cos(lat2)));if(Math.sin(lon2-lon1)>0){brng12=brngA;brng21=2*Math.PI-brngB}else{brng12=2*Math.PI-brngA;brng21=brngB}alpha1=(brng13-brng12+Math.PI)%(2*Math.PI)-Math.PI;alpha2=(brng21-brng23+Math.PI)%(2*Math.PI)-Math.PI;if(Math.sin(alpha1)==0&&Math.sin(alpha2)==0){return null}if(Math.sin(alpha1)*Math.sin(alpha2)<0){return null}alpha3=Math.acos(-Math.cos(alpha1)*Math.cos(alpha2)+Math.sin(alpha1)*Math.sin(alpha2)*Math.cos(dist12));dist13=Math.atan2(Math.sin(dist12)*Math.sin(alpha1)*Math.sin(alpha2),Math.cos(alpha2)+Math.cos(alpha1)*Math.cos(alpha3));lat3=Math.asin(Math.sin(lat1)*Math.cos(dist13)+Math.cos(lat1)*Math.sin(dist13)*Math.cos(brng13));dLon13=Math.atan2(Math.sin(brng13)*Math.sin(dist13)*Math.cos(lat1),Math.cos(dist13)-Math.sin(lat1)*Math.sin(lat3));lon3=lon1+dLon13;lon3=(lon3+Math.PI)%(2*Math.PI)-Math.PI;return new LatLon(lat3.toDeg(),lon3.toDeg())};LatLon.prototype.rhumbDistanceTo=function(i){var e=this._radius;var d=this._lat.toRad(),c=i._lat.toRad();var g=(i._lat-this._lat).toRad();var a=Math.abs(i._lon-this._lon).toRad();var f=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(d/2+Math.PI/4));var b=(!isNaN(g/f))?g/f:Math.cos(d);if(a>Math.PI){a=2*Math.PI-a}var h=Math.sqrt(g*g+b*b*a*a)*e;return h.toPrecisionFixed(4)};LatLon.prototype.rhumbBearingTo=function(a){var e=this._lat.toRad(),d=a._lat.toRad();var b=(a._lon-this._lon).toRad();var f=Math.log(Math.tan(d/2+Math.PI/4)/Math.tan(e/2+Math.PI/4));if(Math.abs(b)>Math.PI){b=b>0?-(2*Math.PI-b):(2*Math.PI+b)}var c=Math.atan2(b,f);return(c.toDeg()+360)%360};LatLon.prototype.rhumbDestinationPoint=function(g,m){var f=this._radius;var j=parseFloat(m)/f;var e=this._lat.toRad(),i=this._lon.toRad();g=g.toRad();var c=e+j*Math.cos(g);var k=c-e;var h=Math.log(Math.tan(c/2+Math.PI/4)/Math.tan(e/2+Math.PI/4));var b=(!isNaN(k/h))?k/h:Math.cos(e);var a=j*Math.sin(g)/b;if(Math.abs(c)>Math.PI/2){c=c>0?Math.PI-c:-(Math.PI-c)}lon2=(i+a+3*Math.PI)%(2*Math.PI)-Math.PI;return new LatLon(c.toDeg(),lon2.toDeg())};LatLon.prototype.lat=function(a,b){if(typeof a=="undefined"){return this._lat}return Geo.toLat(this._lat,a,b)};LatLon.prototype.lon=function(a,b){if(typeof a=="undefined"){return this._lon}return Geo.toLon(this._lon,a,b)};LatLon.prototype.toString=function(a,b){if(typeof a=="undefined"){a="dms"}return Geo.toLat(this._lat,a,b)+", "+Geo.toLon(this._lon,a,b)};if(typeof(String.prototype.toRad)==="undefined"){Number.prototype.toRad=function(){return this*Math.PI/180}}if(typeof(String.prototype.toDeg)==="undefined"){Number.prototype.toDeg=function(){return this*180/Math.PI}}if(typeof(String.prototype.toDeg)==="undefined"){Number.prototype.toPrecisionFixed=function(b){var c=this<0?-this:this;var a=this<0?"-":"";if(c==0){e="0.";while(b--){e+="0"}return e}var d=Math.ceil(Math.log(c)*Math.LOG10E);var e=String(Math.round(c*Math.pow(10,b-d)));if(d>0){l=d-e.length;while(l-->0){e=e+"0"}if(d<e.length){e=e.slice(0,d)+"."+e.slice(d)}}else{while(d++<0){e="0"+e}e="0."+e}return a+e}};
