메뉴 건너뛰기

app

[js] gps좌표를 도분초로 나타내기

박영식2008.07.08 11:39조회 수 4552댓글 0

    • 글자 크기
<script language="JavaScript">
<!--

// This JavaScript was written by Tyler Akins and is licensed under
// the GPL v3 -- http://www.gnu.org/copyleft/gpl.html
// See it on the original site -- http://rumkin.com/tools/gps/degrees.php
// Feel free to copy it to your site as long as you leave this header
// pretty much intact and as long as you are complying with the GPL.

function GetDegreeValue(v)
{
    var vv = "";
    var good = "0123456789.";
    var sign = 1;
    var factor = 1;
    var d = 0;
    var c, oldc;
    
    // Change non-numbers into spaces.
    oldc = ' ';
    for (i = 0; i < v.length; i ++)
    {
        var c = v.charAt(i).toUpperCase();
        if (c == 'W' || c == 'S' || c == '-')
        {
            sign = -1;
        }
        if (good.indexOf(c) < 0)
        {
            c = ' ';
        }
        if (oldc != ' ' || c != ' ')
        {
            vv += c;
            oldc = c;
        }        
    }

    v = new Array();
    v = vv.split(' ');
    
    for (i = 0; i < v.length; i ++)
    {
        d += v[i] * factor;
        factor /= 60;
    }
    
    return d * sign;
}


function DoPrecision(v, p)
{
    return Math.round(v * Math.pow(10, p)) / Math.pow(10, p);
}


function upd(v)
{
    var d, m, sign = '', str;
    
    v = GetDegreeValue(v);
    if (v < 0)
    {
        sign = '-';
        v = - v;
    }
    
    str = sign + DoPrecision(v, 6);
    str += '<br>';
        
    d = Math.floor(v);
    v = (v - d) * 60;
    str += sign + d.toString() + '° ' + DoPrecision(v, 3) + "'";
    str += '<br>';
    
    m = Math.floor(v);
    v = (v - m) * 60;
    str += sign + d.toString() + '° ' + m.toString() + "' " +
        DoPrecision(v, 2) + '"';
        
}

// -->
</script>

위의 소스에 upd안에 스트링형태로 호출한다.
upd('좌표')로 넣으면 str 변수에 좌표가 저장된다.

http://rumkin.com/tools/gps/degrees.php
박영식 (비회원)
    • 글자 크기
[PHP] imagecreatefromjpeg, imagejpeg 함수 (by 박영식) [flash] screen.loadMovie로 이미지 로딩시 속성 설정 (by 박영식)

댓글 달기

이전 1 ... 5 6 7 8 9 10 11 12 13 14다음
첨부 (0)
위로