Javascript 从今天的经纬度生成日出和日落时间';日期

Javascript 从今天的经纬度生成日出和日落时间';日期,javascript,latitude-longitude,Javascript,Latitude Longitude,各位。我正在做一个只使用JavaScript(客户端,而不是服务器端)的项目,我想使用NOAA的脚本,我在另一个线程中找到了该脚本(但作为新用户,我不能列出多个链接),我发现: 我试图做的是,当用户输入纬度和经度并单击“提交”时,它将获得今天的日出/日落数据,并将它们存储在两个变量中(例如日出和日落) 然而,我真的希望他们能把所有的脚本(除了嵌入组合框中的脚本)放在一个单独的JavaScript文件中,这样我就可以将NOAA网站上的JavaScript代码源提供给我一直在做的项目

各位。我正在做一个只使用JavaScript(客户端,而不是服务器端)的项目,我想使用NOAA的脚本,我在另一个线程中找到了该脚本(但作为新用户,我不能列出多个链接),我发现:

我试图做的是,当用户输入纬度和经度并单击“提交”时,它将获得今天的日出/日落数据,并将它们存储在两个变量中(例如日出和日落)

然而,我真的希望他们能把所有的脚本(除了嵌入组合框中的脚本)放在一个单独的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>
如您所见,字段集中的两个文本框在从XML文件填充时被写入。虽然我正在做一个项目作为概念证明,但我找不到一种方法将所有数据保存到XML文件中,所以我的老师告诉我不要担心这一点。但是,由于我编写了一个以表格格式动态填充所有XML数据的代码,我一直在互联网上寻找一个特定的JavaScript代码,或者是一个可以从我的项目链接到的JavaScript文件,但是使用我从NOAA为我的个人项目借用的JavaScript代码,有人知道如何根据纬度、经度和今天的日期计算日出/日落时间吗

更新

看起来我在互联网上找到了一些东西(我在谷歌上搜索了:sunrise sunset web服务):


我使用关键字“sunrise sunset JavaScript”(不带引号)进行了搜索,我花了一段时间进行搜索,但用“web服务”替换了“JavaScript”,我能够找到我要找的网站,但我真的认为,在涉及“同源策略”时,XMLHttpRequest无法做到这一点在IE8/9中,这是为了防止跨站点脚本编写。

我为sunrise和sunset创建了一个javascript计算器,并将其放在github上。这是基于国家可再生能源实验室公布的计算结果。我已尝试使其易于使用,但欢迎您提交改进。

刚刚遇到这个问题。您是根据哪个许可证发布的?在你的回购协议中找不到。对不起,我最终会抽出时间来解决的。我打算让它获得麻省理工学院的许可。基本上相同的问题,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();
        }
    }
}