地圖經緯度座標相互轉換度分秒
阿新 • • 發佈:2018-11-10
經緯度座標轉換度分秒
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