地図の経緯度の座標は互いに度の分秒を転換します.

893 ワード

経緯度座標変換度分秒
function changeToDFM(du) {
    const arr1 = du.split(".");
    const d = arr1[0];
    let tp = "0." + arr1[1]
    tp = String(tp * 60); //           
    const arr2 = tp.split(".");
    const f = arr2[0];
    tp = "0." + arr2[1];
    tp = tp * 60;
    const m = tp;
    const dfm = d + "°" + f + "'" + m + "\"";
    return dfm;
}
console.log(changeToDFM('113.211'))
//113°12'39.6"
経緯度分秒変換座標系
function changeToDu(dfm) {
    const arr1 = dfm.split('°');
    const d = arr1[0];
    const arr2 = arr1[1].split("'")
    let f = arr2[0] || 0;
    const m = arr2[1] || 0;
    f = parseFloat(f) + parseFloat(m / 60);
    var du = parseFloat(f / 60) + parseFloat(d);
    return du;
}
console.log(changeToDu("113°12'39.6"))
//113.211