MrMufflon / Leaflet.Coordinates

Leaflet plugin to view mouse coordinates
http://mrmufflon.github.io/Leaflet.Coordinates/
Other
104 stars 55 forks source link

Incorrect DMS coordinates #16

Closed oscarhidalgo closed 9 years ago

oscarhidalgo commented 9 years ago

On negative longitude the DMS coordinates are wrong.

image image

oscarhidalgo commented 9 years ago

On toDMS function you ca't use only Math.floor because on negative values this return an incorrect value. For example the Math.floor(-8.76) is -9

You can change the code, for example:

toDMS : function (deg) {
    var d = Math.floor(Math.abs(deg));
    var minfloat = (Math.abs(deg)-d)*60;
    var m = Math.floor(minfloat);
    var secfloat = (minfloat-m)*60;
    var s = Math.round(secfloat);
    if (s==60) {
        m++;
        s="00";
    }
    if (m==60) {
        d++;
        m="00";
    }
    if(s<10) {
        s="0"+s;
    }
    if(m<10){
        m="0"+m;
    }
            var dir = "";
            if (deg < 0)
            {
                   dir="-";
            }
            else
            {
                   dir="";
            }

    return ("" + dir + d + "&deg; " + m + "' " + s + "''");
},
MrMufflon commented 9 years ago

Thanks! Fixed it and also added Jasmine tests to verify. Created a new release 0.1.4 dc2a7e88848135aeaf34c68ff85c5d0aecca2edd