在当日依据纬度经度生成日出和日落时间
||
大家。我正在做一个仅使用JavaScript(客户端,而不是服务器端)的项目,并且我想使用在另一个线程中找到的NOAA中的脚本(我不能列出多个链接)但是作为一个新用户),我发现了这一点:
http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html
我正在尝试做的是,当用户输入经度和纬度并单击“提交”时,它将获取今天的日出/日落数据并将其存储在两个变量中(例如,日出和日落) )。
但是,我真的希望他们可以将所有脚本(嵌入组合框的脚本除外)都放在单独的JavaScript文件中,以便我可以将NOAA网站的JavaScript代码源提供给我的项目, \一直在努力。
<div id=\"locationSetupDiv\">
<fieldset>
<legend>Location</legend>
<p>
<a href=\"javascript:var load = window.open(\'http://www.esrl.noaa.gov/gmd/grad/solcalc/\')\">
Get your longitude and latitude from here.</a>
</p>
<table class=\"inputData\">
<tr>
<th style=\"width: 75px;\">
<label id=\"labelLongitude\" for=\"inputModuleIDNumber\">
Longitude:</label></th>
<td><input id=\"inputLongitude\" /></td>
</tr>
<tr>
<th><label id=\"labelLatitude\" for=\"inputModuleName\">
Latitude:</label></th>
<td><input id=\"inputLatitude\" /></td>
</tr>
</table>
<input type=\"button\" value=\"Submit Changes\"
style=\"float: right; margin-top: 1em;\" />
</fieldset>
</div>
上面的代码是HTML。现在,这是我的JavaScript代码:
function PopulateFromXML()
{
listModules = document.getElementById(
\"listModules\").getElementsByTagName(\"tbody\");
// Gather the text fields for location data.
inputLongitude = document.getElementById(\"inputLongitude\")
inputLatitude = document.getElementById(\"inputLatitude\")
// Firefox\'s DOM Parser treats whitespaces as text nodes, including
// line breaks.
removeWhitespace(xmlDoc.documentElement);
// Send the document\'s root element to the XML Object variable.
xmlObj = xmlDoc.documentElement;
// Perform the checks and populate the tables
// and any other elements that are needed.
if (xmlObj.tagName == \"HomeAutomationInterface\")
{
// Check to be sure the first node is the \"Setup\" node. It contains the
// location node.
if ((xmlObj.childNodes[0].tagName == \"Setup\") &&
(xmlObj.childNodes[0].childNodes[0].tagName == \"Location\"))
{
// Copy the data from one of the attributes to the respective text boxes.
inputLongitude.value = xmlObj.childNodes[0]
.childNodes[0].getAttribute(\"longitude\");
inputLatitude.value = xmlObj.childNodes[0]
.childNodes[0].getAttribute(\"latitude\");
}
// The second node within the root element is Modules node.
// This will be implemented.
if (xmlObj.childNodes[1].tagName == \"Modules\")
{
ListModulesInTabularData();
}
// The third node within the root element is Scenes node.
// You need modules in order for scenes to work.
// This will be implemented.
if (xmlObj.childNodes[2].tagName == \"Scenes\")
{
ListScenesInTabularData();
}
// The last element is the Timers node.
// This will either activate the scene or turn on, off,
// dim, brighten, or set the light level of the module if
// it is the light module or turn on or off the appliance
// module. This will be implemented.
if (xmlObj.childNodes[3].tagName == \"Timers\")
{
ListTimersInTabularData();
}
}
}
如您所见,当从XML文件中填充字段集时,两个文本框将被写入。尽管我正在做一个项目的概念证明,但是我找不到将所有数据保存到XML文件的方法,所以我的老师告诉我不要担心。但是,由于我已经编写了以表格格式动态填充所有XML数据的代码,因此我一直在寻找Internet上特定的JavaScript代码,或者寻找可以从项目中链接到的JavaScript文件,但是借助我从NOAA借来的个人项目的JavaScript代码,有人知道如何根据纬度,经度和今天的日期获得日出/日落时间吗?
更新资料
好像我在Internet上找到了一些东西(我在Google上搜索过:Sunrise Sunset Web服务):
http://www.earthtools.org/webservices.htm
我使用关键字“日出日落JavaScript”(不带引号)进行了搜索,花了我一段时间,但随后用“ JavaScript”替换为“ Web服务”,就可以找到一个网站\正在寻找,但是后来我真的认为,当涉及到IE8 / 9中的“相同来源策略”时,XMLHttpRequest不能用于XMLHttpRequest,这是为了防止跨站点脚本编写。
没有找到相关结果
已邀请:
1 个回复
细屠截殴些