/* 205.395583333332 = 205°23'44.1" 1,直接读取"度":205 2,(205.395583333332-205)*60=23.734999999920 得到"分":23 3,(23.734999999920-23)*60=44.099999995200 得到"秒":44.1 return string, */ function latLngDecimalToDegrees(decimal) { let absDecimal = Math.abs(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 + '″'; } /* Decimal Degrees = Degrees + minutes/60 + seconds/3600 例:57°55'56.6" =57+55/60+56.6/3600=57.9323888888888 return Float or NaN */ function latLngDegreesToDecimal(degreesStr) { let degreesArr = degreesStr.split("°"); let degrees = degreesArr[0]; let isNegative = Math.abs(degrees) != degrees; if (degreesArr.length == 1) { return parseInt(degrees); } let minutesArr = degreesArr[1].split("′"); let minutes = minutesArr[0]; if (minutesArr.length == 1) { return parseFloat((isNegative ? "-" : "") + (Math.abs(degrees) + Math.abs(minutes) / 60)); } let secondsStr = minutesArr[1]; let secondsArr = secondsStr.split('″'); let seconds = secondsArr[0]; return parseFloat((isNegative ? "-" : "") + (Math.abs(degrees) + Math.abs(minutes) / 60 + Math.abs(seconds) / 3600)); } function isObject(arg) { return typeof arg === 'object' && arg !== null; } function isUndefined(arg) { return arg === void 0; } function isString(arg) { return typeof arg === 'string'; } function hasLine(obj) { return (isObject(obj) && isSafeString(obj.addr) && isSafeString(obj.lat) && isSafeString(obj.lng)); } function isSafeString(arg) { if (isUndefined(arg)) { return false; } if (!isString(arg)) { return false; } if (arg.length == 0) { return false; } return true; } function hasPoint(obj) { return (isObject(obj) && isSafeString(obj.lat) && isSafeString(obj.lng)); } module.exports = { latLngDecimalToDegrees, latLngDegreesToDecimal, isObject, isUndefined, isString, isSafeString, hasLine, hasPoint }