浏览代码

修复秒是 60 没有进位的问题

wd 7 年之前
父节点
当前提交
653a573c9b
共有 1 个文件被更改,包括 12 次插入5 次删除
  1. 12 5
      Utils.js

+ 12 - 5
Utils.js

@@ -1,4 +1,5 @@
 
 
+
 /*
 /*
     205.395583333332 = 205°23'44.1"
     205.395583333332 = 205°23'44.1"
     1,直接读取"度":205
     1,直接读取"度":205
@@ -9,10 +10,16 @@
 function latLngDecimalToDegrees(decimal) {
 function latLngDecimalToDegrees(decimal) {
     let absDecimal = Math.abs(decimal);
     let absDecimal = Math.abs(decimal);
     let isNegative = Math.abs(decimal) != decimal;
     let isNegative = Math.abs(decimal) != decimal;
-    let degrees = Math.floor(absDecimal); //度
-    let minutes = Math.floor((absDecimal - degrees) * 60);  //分
-    let seconds = Math.round((absDecimal - degrees) * 3600 % 60);  //秒
-    return (isNegative ? "-" : "") + degrees + '°' + minutes + "′" + seconds + '″';
+    let d = Math.floor(absDecimal); //度
+    let m = Math.floor((absDecimal - d) * 60);  //分
+    let s = Math.round((absDecimal - d) * 3600 % 60);  //秒
+    if(s == 60) {s = 0; m++}
+    if(m == 60) {m = 0; d++}
+    //d = ('000'+d).slice(-3);                   // left-pad with leading zeros
+    m = ('00'+m).slice(-2);                    // left-pad with leading zeros
+    s = ('00'+s).slice(-2);
+    //if (s<10) s = '0' + s;                     // left-pad with leading zeros (note may include decimals)
+    return (isNegative ? "-" : "") + d + '°' + m + "′" + s + '″';
 }
 }
 
 
 /*
 /*
@@ -89,4 +96,4 @@ module.exports = {
     isSafeString,
     isSafeString,
     hasLine,
     hasLine,
     hasPoint
     hasPoint
-}
+}