最佳答案
如何修改此代码,以便在任何小于10的数字之前添加0
$('#detect').html( toGeo(apX, screenX) + latT +', '+ toGeo(apY, screenY) + lonT );
function toGeo(d, max) {
var c = '';
var r = d/max * 180;
var deg = Math.floor(r);
c += deg + "° ";
r = (r - deg) * 60;
var min = Math.floor(r);
c += min + "′ ";
r = (r - min) * 60;
var sec = Math.floor(r);
c += sec + "″";
return c;
}
所以输出会从
4 ° 7′34′′ W,168 ° 1′23′ N
到
04 ° 07′34′ W,168 ° 01′23′ N
谢谢你抽出时间