程度符号显示奇怪的字符

时间:2016-03-14 12:30:11

标签: jquery

我有一个jquery脚本,可以将谷歌地图坐标转换为十进制格式。

function getDD2DMS(dms, type){

    var sign = 1, Abs=0;
    var days, minutes, secounds, direction;

    if(dms < 0)  { sign = -1; }
    Abs = Math.abs( Math.round(dms * 1000000.));
    //Math.round is used to eliminate the small error caused by rounding in the computer:
    //e.g. 0.2 is not the same as 0.20000000000284
    //Error checks
    if(type == "lat" && Abs > (90 * 1000000)){
        //alert(" Degrees Latitude must be in the range of -90. to 90. ");
        return false;
    } else if(type == "lon" && Abs > (180 * 1000000)){
        //alert(" Degrees Longitude must be in the range of -180 to 180. ");
        return false;
    }

    days = Math.floor(Abs / 1000000);
    minutes = Math.floor(((Abs/1000000) - days) * 60);
    secounds = ( Math.floor((( ((Abs/1000000) - days) * 60) - minutes) * 100000) *60/100000 ).toFixed();
    days = days * sign;
    if(type == 'lat') direction = days<0 ? 'S' : 'N';
    if(type == 'lon') direction = days<0 ? 'W' : 'E';
    //else return value     
    return (days * sign) + 'ยบ ' + minutes + "' " + secounds + "'' " + direction;
}

几个月来它完美无缺,显示结果如下:

enter image description here

现在突然间,它显示了一个奇怪的角色(ยบ)而不是度数符号。我意识到我的脚本中有这个符号,但我不知道它的作用,因为脚本是一个用于映射的库:

enter image description here

1 个答案:

答案 0 :(得分:0)

应该在那里使用

&deg; html实体:

function getDD2DMS(dms, type){
    return 66 + '&deg;';
}

document.body.innerHTML = getDD2DMS();