所以我有这段代码是为了做这个等式:
(1 / 15) * arccos(-tan(L) * tan(23.44 * sin(360 * (D + 284) / 365)))
并出于测试目的提醒它!但由于某种原因,它返回“NaN”。我可能做了一些非常愚蠢的事情:P
var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var d = Math.floor(diff / oneDay);
var lat = position.coords.latitude;
var long = position.coords.longitude;
var tanlat = Math.atan(lat);
var tantwentythree = Math.tan(23.44);
var dayplus = d + 284;
var sinday = Math.sin(360 * dayplus);
var arccos = Math.acos(tanlat);
var start = 1 / 15;
var equation = start * arccos * tantwentythree * sinday / 365;
alert(equation);
var result = rad2deg / 15 * Math.acos(-Math.tan(lat*deg2rad) * Math.tan(23.44*deg2rad * Math.sin(360*deg2rad * (day + 284) / 365)));
alert(result);
var resultstr = string(result);
document.getElementById('sunrise').innerHTML = resultstr;
我有一个 id 为“sunrise”的,当函数运行时,var resultstr 应该被添加到(我认为?)但我没有!