AnalysisSystemForRadionucli.../src/utils/map.js

14 lines
593 B
JavaScript
Raw Normal View History

2023-06-16 18:58:31 +08:00
/**
* 将十进制度格式的经度转换为度分秒
* @param {*} decimal
* @param {*} isLongitude 是不是经度
* @returns
*/
export function decimalToDms(decimal, isLongitude = true) {
const degrees = Math.floor(decimal);
const decimalMinutes = (decimal - degrees) * 60;
const minutes = Math.floor(decimalMinutes);
const seconds = parseInt((decimalMinutes - minutes) * 60);
const tail = isLongitude ? (decimal > 0 ? 'E' : decimal < 0 ? 'W' : '') : (decimal > 0 ? 'N' : decimal < 0 ? 'S' : '')
return `${Math.abs(degrees)}°${minutes}'${seconds}"${tail}`;
}