我有一个公式将DMS GPS坐标转换为十进制度,
然而我试图在JS中使用它而不是工作,
在测试过程中,我注意到了' latlng'是正确的拆分,但一旦我尝试使用Math.trunc它只是停止提供数据
这是功能:
function convertdec() {
var input1 = document.getElementById('latlng').value;
var latlongc = input1.split( ',' ,2);
var latdeg1 = Math.trunc(parseInt(latlngc[0]));
var latmin1 = Math.trunc((parseInt(latlngc[0])-latdeg1)*60);
var latsec1 = (((parseInt(latlngc[0])-latdeg1)*60)-latmin1)*60;
var longdeg1 = Math.trunc(parseInt(latlngc[1]));
var longmin1 = Math.trunc((parseInt(latlngc[1])-longdeg1)*60);
var longsec1 = (((parseInt(latlngc[0])-latdeg1)*60)-longmin1)*60;
document.getElementById('deg1').value = latdeg1;
document.getElementById('min1').value = latmin1;
document.getElementById('sec1').value = latsec1;
document.getElementById('deg2').value = longdeg1;
document.getElementById('min2').value = longmin1;
document.getElementById('sec2').value = longsec1;
}
布局对于公式是正确的,但显然不适用于脚本
请协助解释我做错了什么
答案 0 :(得分:0)
修正了它
function convertdec() {
var input1 = document.getElementById('latlng').value;
var latlngc = input1.split( ',' ,2);
var latdeg1 = Math.floor(parseInt(latlngc[0]));
var latmin01 = (latlngc[0]-latdeg1)*60;
var latmin1 = Math.floor(latmin01);
var latsec01 = (latmin01-latmin1);
var latsec1 = latsec01*60;
var longdeg1 = Math.floor(parseInt(latlngc[1]));
var longmin01 = (latlngc[1]-longdeg1)*60;
var longmin1 = Math.floor(longmin01);
var longsec01 = (longmin01-longmin1)
var longsec1 = longsec01*60
document.getElementById('deg1').value = latdeg1;
document.getElementById('min1').value = latmin1;
document.getElementById('sec1').value = latsec1;
document.getElementById('deg2').value = longdeg1;
document.getElementById('min2').value = longmin1;
document.getElementById('sec2').value = longsec1;
}