Skip to content
Browse files

Added 1 more radix parameter

  • Loading branch information...
1 parent de2587d commit 1f03c72483486e6a412e4aa9faf3a7abc4f4b1e6 @manuelbieh committed Aug 31, 2011
Showing with 5 additions and 5 deletions.
  1. +3 −3 geolib.js
  2. +2 −2 geolib.min.js
View
6 geolib.js
@@ -5,7 +5,7 @@
*
* @author Manuel Bieh
* @url http://www.manuel-bieh.de/
- * @version 1.1.3
+ * @version 1.1.4
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
*
*/
@@ -154,7 +154,7 @@
var distance = b * A * (sigma - deltaSigma);
distance = distance.toFixed(3); // round to 1mm precision
- return geolib.distance = parseInt(Math.round(distance/accuracy)*accuracy)
+ return geolib.distance = parseInt(Math.round(distance/accuracy)*accuracy, 10)
/*
// note: to return initial/final bearings in addition to distance, use something like:
@@ -178,7 +178,7 @@
*/
getDistanceSimple: function(start, end, accuracy) {
- accuracy = parseInt(accuracy) || 1;
+ accuracy = parseInt(accuracy, 10) || 1;
var coord1 = {}, coord2 = {};
coord1.latitude = parseFloat(geolib.useDecimal(start.latitude)).toRad();
View
4 geolib.min.js
@@ -5,8 +5,8 @@
*
* @author Manuel Bieh
* @url http://www.manuel-bieh.de/
- * @version 1.1.3
+ * @version 1.1.4
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
*
*/
-(function(a,b){var c=6378137;var d=/^([0-9]{1,3})°\s*([0-9]{1,3})'\s*(([0-9]{1,3}(\.([0-9]{1,2}))?)"\s*)?([NEOSW]?)$/;var e={decimal:{},sexagesimal:{},distance:0,getDistance:function(a,b,c){c=parseInt(c)||1;var d={},f={};d.latitude=e.useDecimal(a.latitude);d.longitude=e.useDecimal(a.longitude);f.latitude=e.useDecimal(b.latitude);f.longitude=e.useDecimal(b.longitude);var g=6378137,h=6356752.314245,i=1/298.257223563;var j=(f.longitude-d.longitude).toRad();var k=Math.atan((1-i)*Math.tan(parseFloat(d.latitude).toRad()));var l=Math.atan((1-i)*Math.tan(parseFloat(f.latitude).toRad()));var m=Math.sin(k),n=Math.cos(k);var o=Math.sin(l),p=Math.cos(l);var q=j,r,s=100;do{var t=Math.sin(q),u=Math.cos(q);var v=Math.sqrt(p*t*p*t+(n*o-m*p*u)*(n*o-m*p*u));if(v==0){return e.distance=0}var w=m*o+n*p*u;var x=Math.atan2(v,w);var y=n*p*t/v;var z=1-y*y;var A=w-2*m*o/z;if(isNaN(A)){A=0}var B=i/16*z*(4+i*(4-3*z));r=q;q=j+(1-B)*i*y*(x+B*v*(A+B*w*(-1+2*A*A)))}while(Math.abs(q-r)>1e-12&&--s>0);if(s==0){return NaN}var C=z*(g*g-h*h)/(h*h);var D=1+C/16384*(4096+C*(-768+C*(320-175*C)));var E=C/1024*(256+C*(-128+C*(74-47*C)));var F=E*v*(A+E/4*(w*(-1+2*A*A)-E/6*A*(-3+4*v*v)*(-3+4*A*A)));var G=h*D*(x-F);G=G.toFixed(3);return e.distance=parseInt(Math.round(G/c)*c)},getDistanceSimple:function(a,b,d){d=parseInt(d)||1;var f={},g={};f.latitude=parseFloat(e.useDecimal(a.latitude)).toRad();f.longitude=parseFloat(e.useDecimal(a.longitude)).toRad();g.latitude=parseFloat(e.useDecimal(b.latitude)).toRad();g.longitude=parseFloat(e.useDecimal(b.longitude)).toRad();var h=Math.round(Math.acos(Math.sin(g.latitude)*Math.sin(f.latitude)+Math.cos(g.latitude)*Math.cos(f.latitude)*Math.cos(f.longitude-g.longitude))*c);return e.distance=parseInt(Math.round(h/d)*d)},getCenter:function(a){max=function(a){return Math.max.apply(Math,a)};min=function(a){return Math.min.apply(Math,a)};var b,c,d={lat:[],lng:[]};for(coord in a){d.lat.push(e.useDecimal(a[coord].latitude));d.lng.push(e.useDecimal(a[coord].longitude))}var f=min(d.lat);var g=min(d.lng);var h=max(d.lat);var i=max(d.lng);b=((f+h)/2).toFixed(6);c=((g+i)/2).toFixed(6);var j=e.convertUnit("km",e.getDistance(f,g,h,i));return{latitude:b,longitude:c,distance:j}},isPointInside:function(a,b){for(var c=false,d=-1,e=b.length,f=e-1;++d<e;f=d){(b[d].longitude<=a.longitude&&a.longitude<b[f].longitude||b[f].longitude<=a.longitude&&a.longitude<b[d].longitude)&&a.latitude<(b[f].latitude-b[d].latitude)*(a.longitude-b[d].longitude)/(b[f].longitude-b[d].longitude)+b[d].latitude&&(c=!c)}return c},isPointInCircle:function(a,b,c){return e.getDistance(a,b)<c},orderByDistance:function(a,b){var c=[];for(coord in b){var d=e.getDistance(a,b[coord]);c.push({key:coord,latitude:b[coord].latitude,longitude:b[coord].longitude,distance:d})}return c.sort(function(a,b){return a.distance-b.distance})},findNearest:function(a,b,c){c=c||0;var d=e.orderByDistance(a,b);return d[c]},getPathLength:function(a){var b=0,c;for(coord in a){if(c){b+=e.getDistance(a[coord],c)}c=a[coord]}return b},convertUnit:function(a,b,c){if(b==0||typeof b=="undefined"){if(e.distance==0){return 0}else{b=e.distance}}a=a||"m";c=c||4;switch(a){case"m":return e.round(b,c);break;case"km":return e.round(b/1e3,c);break;case"cm":return e.round(b*100,c);break;case"mm":return e.round(b*1e3,c);break;case"mi":return e.round(b*(1/1609.344),c);break;case"sm":return e.round(b*(1/1852.216),c);break;case"ft":return e.round(b*(100/30.48),c);break;case"in":return e.round(b*100/2.54,c);break;case"yd":return e.round(b*(1/.9144),c);break}return b},useDecimal:function(a){a=a.toString().replace(/\s*/,"");if(!isNaN(parseFloat(a))&&parseFloat(a).toString()==a){return a}else if(e.isSexagesimal(a)==true){return e.sexagesimal2decimal(a)}else{throw"Unknown format."}},decimal2sexagesimal:function(a){tmp=a.toString().split(".");var b=tmp[0];var c=("0."+tmp[1])*60;var d=c.toString().split(".");c=parseInt(c);d=(("0."+d[1])*60).toFixed(2);e.sexagesimal[a]=b+"° "+c+"' "+d+'"';return e.sexagesimal[a]},sexagesimal2decimal:function(a){var b=new RegExp(d);var c=b.exec(a);if(!!c){var f=parseFloat(c[2]/60);var g=parseFloat(c[4]/3600)||0}var h=(parseFloat(c[1])+f+g).toFixed(8);h=c[7]=="S"||c[7]=="W"?h*-1:h;e.decimal[a]=h;return h},isSexagesimal:function(a){return d.test(a)},round:function(a,b){var c=Math.pow(10,b);return Math.round(a*c)/c}};if(typeof Number.prototype.toRad==="undefined"){Number.prototype.toRad=function(){return this*Math.PI/180}}a.geolib=e})(this)
+;(function(a,b){var c=6378137;var d=/^([0-9]{1,3})°\s*([0-9]{1,3})'\s*(([0-9]{1,3}(\.([0-9]{1,2}))?)"\s*)?([NEOSW]?)$/;var e={decimal:{},sexagesimal:{},distance:0,getDistance:function(a,b,c){c=parseInt(c,10)||1;var d={},f={};d.latitude=e.useDecimal(a.latitude);d.longitude=e.useDecimal(a.longitude);f.latitude=e.useDecimal(b.latitude);f.longitude=e.useDecimal(b.longitude);var g=6378137,h=6356752.314245,i=1/298.257223563;var j=(f.longitude-d.longitude).toRad();var k=Math.atan((1-i)*Math.tan(parseFloat(d.latitude).toRad()));var l=Math.atan((1-i)*Math.tan(parseFloat(f.latitude).toRad()));var m=Math.sin(k),n=Math.cos(k);var o=Math.sin(l),p=Math.cos(l);var q=j,r,s=100;do{var t=Math.sin(q),u=Math.cos(q);var v=Math.sqrt(p*t*p*t+(n*o-m*p*u)*(n*o-m*p*u));if(v==0){return e.distance=0}var w=m*o+n*p*u;var x=Math.atan2(v,w);var y=n*p*t/v;var z=1-y*y;var A=w-2*m*o/z;if(isNaN(A)){A=0}var B=i/16*z*(4+i*(4-3*z));r=q;q=j+(1-B)*i*y*(x+B*v*(A+B*w*(-1+2*A*A)))}while(Math.abs(q-r)>1e-12&&--s>0);if(s==0){return NaN}var C=z*(g*g-h*h)/(h*h);var D=1+C/16384*(4096+C*(-768+C*(320-175*C)));var E=C/1024*(256+C*(-128+C*(74-47*C)));var F=E*v*(A+E/4*(w*(-1+2*A*A)-E/6*A*(-3+4*v*v)*(-3+4*A*A)));var G=h*D*(x-F);G=G.toFixed(3);return e.distance=parseInt(Math.round(G/c)*c,10)},getDistanceSimple:function(a,b,d){d=parseInt(d,10)||1;var f={},g={};f.latitude=parseFloat(e.useDecimal(a.latitude)).toRad();f.longitude=parseFloat(e.useDecimal(a.longitude)).toRad();g.latitude=parseFloat(e.useDecimal(b.latitude)).toRad();g.longitude=parseFloat(e.useDecimal(b.longitude)).toRad();var h=Math.round(Math.acos(Math.sin(g.latitude)*Math.sin(f.latitude)+Math.cos(g.latitude)*Math.cos(f.latitude)*Math.cos(f.longitude-g.longitude))*c);return e.distance=parseInt(Math.round(h/d)*d,10)},getCenter:function(a){var b=function(a){return Math.max.apply(Math,a)};var c=function(a){return Math.min.apply(Math,a)};var d,f,g={lat:[],lng:[]};for(var h in a){g.lat.push(e.useDecimal(a[h].latitude));g.lng.push(e.useDecimal(a[h].longitude))}var i=c(g.lat);var j=c(g.lng);var k=b(g.lat);var l=b(g.lng);d=((i+k)/2).toFixed(6);f=((j+l)/2).toFixed(6);var m=e.convertUnit("km",e.getDistance(i,j,k,l));return{latitude:d,longitude:f,distance:m}},isPointInside:function(a,b){for(var c=false,d=-1,e=b.length,f=e-1;++d<e;f=d){(b[d].longitude<=a.longitude&&a.longitude<b[f].longitude||b[f].longitude<=a.longitude&&a.longitude<b[d].longitude)&&a.latitude<(b[f].latitude-b[d].latitude)*(a.longitude-b[d].longitude)/(b[f].longitude-b[d].longitude)+b[d].latitude&&(c=!c)}return c},isPointInCircle:function(a,b,c){return e.getDistance(a,b)<c},orderByDistance:function(a,b){var c=[];for(var d in b){var f=e.getDistance(a,b[d]);c.push({key:d,latitude:b[d].latitude,longitude:b[d].longitude,distance:f})}return c.sort(function(a,b){return a.distance-b.distance})},findNearest:function(a,b,c){c=c||0;var d=e.orderByDistance(a,b);return d[c]},getPathLength:function(a){var b=0,c;for(var d in a){if(c){b+=e.getDistance(a[d],c)}c=a[d]}return b},convertUnit:function(a,b,c){if(b==0||typeof b=="undefined"){if(e.distance==0){return 0}else{b=e.distance}}a=a||"m";c=c||4;switch(a){case"m":return e.round(b,c);break;case"km":return e.round(b/1e3,c);break;case"cm":return e.round(b*100,c);break;case"mm":return e.round(b*1e3,c);break;case"mi":return e.round(b*(1/1609.344),c);break;case"sm":return e.round(b*(1/1852.216),c);break;case"ft":return e.round(b*(100/30.48),c);break;case"in":return e.round(b*100/2.54,c);break;case"yd":return e.round(b*(1/.9144),c);break}return b},useDecimal:function(a){a=a.toString().replace(/\s*/,"");if(!isNaN(parseFloat(a))&&parseFloat(a).toString()==a){return a}else if(e.isSexagesimal(a)==true){return e.sexagesimal2decimal(a)}else{throw"Unknown format."}},decimal2sexagesimal:function(a){if(a in e.sexagesimal){return e.sexagesimal[a]}var b=a.toString().split(".");var c=b[0];var d=("0."+b[1])*60;var f=d.toString().split(".");d=parseInt(d,10);f=(("0."+f[1])*60).toFixed(2);e.sexagesimal[a]=c+"° "+d+"' "+f+'"';return e.sexagesimal[a]},sexagesimal2decimal:function(a){if(a in e.decimal){return e.decimal[a]}var b=new RegExp(d);var c=b.exec(a);if(c){var f=parseFloat(c[2]/60);var g=parseFloat(c[4]/3600)||0}var h=(parseFloat(c[1])+f+g).toFixed(8);h=c[7]=="S"||c[7]=="W"?h*-1:h;e.decimal[a]=h;return h},isSexagesimal:function(a){return d.test(a)},round:function(a,b){var c=Math.pow(10,b);return Math.round(a*c)/c}};if(typeof Number.prototype.toRad==="undefined"){Number.prototype.toRad=function(){return this*Math.PI/180}}a.geolib=e})(this)

0 comments on commit 1f03c72

Please sign in to comment.
Something went wrong with that request. Please try again.