From b13196218b784d776d70c7bd249511e98621e97b Mon Sep 17 00:00:00 2001 From: Xu Zhimeng Date: Sun, 25 Jun 2023 15:55:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=8F=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6=E8=BD=AC=E6=8D=A2=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/map.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/map.js b/src/utils/map.js index 6c80e69..fdec3ab 100644 --- a/src/utils/map.js +++ b/src/utils/map.js @@ -5,10 +5,10 @@ * @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 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 `${Math.abs(degrees)}°${minutes}'${seconds}"${tail}`; + return `${degree}°${minute}'${second}"${tail}` } \ No newline at end of file