14 lines
602 B
JavaScript
14 lines
602 B
JavaScript
/**
|
|
* 将十进制度格式的经度转换为度分秒
|
|
* @param {*} decimal
|
|
* @param {*} isLongitude 是不是经度
|
|
* @returns
|
|
*/
|
|
export function decimalToDms(decimal, isLongitude = true) {
|
|
const absoluteValue = Math.abs(decimal)
|
|
const degree = Math.floor(absoluteValue)
|
|
const minute = Math.floor((absoluteValue - degree) * 60);
|
|
const second = Math.round(((absoluteValue - degree) * 60 - minute) * 60)
|
|
const tail = isLongitude ? (decimal > 0 ? 'E' : decimal < 0 ? 'W' : '') : (decimal > 0 ? 'N' : decimal < 0 ? 'S' : '')
|
|
return `${degree}°${minute}'${second}"${tail}`
|
|
} |