首页 > 解决方案 > api.weather.gov 开始和结束时间

问题描述

我一直在使用来自weather.gov的相对较新的 V3 API 的警报功能。我已经成功地使用 API 在https://api.weather.gov/alerts/active上使用 PHP 查看当前警报,并在 HTTP 请求中发送适当的接受、版本和用户代理标头。

我现在希望扩展它以允许查询特定日期的非活动警报。该文档以ISO8601DateTime格式说明了开始和结束参数。因此,以下示例 URL 应生成 2018 年 5 月 15 日在伊利诺伊州的所有警报列表:

https://api.weather.gov/alerts?start=2018-05-14T00:00:00-05:00&end=2018-05-15T00:00:00-05:00&state=IL

然而,这会产生响应:

{
   "type": "FeatureCollection",
   "features": [],
   "title": "Watches, warnings, and advisories issued between Mon, May 14, 2018 12:00:00 AM -0500 and Tue, May 14, 2018 12:00:00 AM -0500 for Illinois"
}

响应清楚地表明正在正确解析参数。我知道今天整个伊利诺伊州都发布了很多警报。我还尝试了许多更短和更长的持续时间、不同时区(包括无)、不同日期和不同状态的变体,包括没有提供状态。它们都提供了描述列表的类似结果,但没有实际数据。

是否有人在 API 上找到了更好的文档,或者在警报开始和结束时间方面取得了成功?

您可以在此处找到 API 的(内)完整文档。

标签: phpjson

解决方案


我玩了一圈,最终只是看看你在 IL 中通过一个简单的请求得到了什么。

https://api.weather.gov/alerts?state=IL

然后我使用有效而不是开始和结束。

https://api.weather.gov/alerts?state=IL&effective=2018-05-20T06:08:00-04:00

你会得到一些东西:

    {
        "@context": [
    "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
    {
        "wx": "https://api.weather.gov/ontology#",
        "@vocab": "https://api.weather.gov/ontology#"
    }
],
"type": "FeatureCollection",
"features": [
    {
        "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-2847567-2622897",
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        -90.97,
                        39.39
                    ],
                    [
                        -90.89,
                        39.45
                    ],
                    [
                        -90.77,
                        39.38
                    ],
                    [
                        -90.71,
                        39.23
                    ],
                    [
                        -90.81,
                        39.22
                    ],
                    [
                        -90.97,
                        39.39
                    ]
                ]
            ]
        },

推荐阅读