메뉴 건너뛰기

app

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

박영식2008.07.08 11:39조회 수 4826댓글 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 박영식)

댓글 달기

박영식
2010.09.09 조회 4901
박영식
2010.05.25 조회 4248
박영식
2010.01.14 조회 5086
박영식
2009.09.21 조회 4267
박영식
2008.08.18 조회 6186
박영식
2008.08.17 조회 4375
박영식
2008.07.24 조회 4790
박영식
2008.07.23 조회 8139
박영식
2008.07.22 조회 3463
박영식
2008.04.11 조회 2316
박영식
2008.01.20 조회 2161
박영식
2007.12.23 조회 3330
첨부 (0)
위로