如何通过 Web 服务获取当前天气

发布于 2024-08-25 22:42:10 字数 1539 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

老旧海报 2024-09-01 22:42:10

有许多天气 API 可以根据邮政编码查找天气,或者找到最近的邮政编码。请参阅此问题

国家气象局有一个 REST API。 CTRL+F 获取邮政编码:

一个或多个邮政编码的汇总数据:返回一个或多个邮政编码的 DWML 编码的 NDFD 数据(50 个美国和波多黎各)。

这是一个请求示例


我不确定该请求是否符合当前条件。如果没有,您可以使用 Wunderground API。首先,您使用 GeolookupXML 根据城市查找附近的气象站(请参阅示例输出中的 nearby_weather_stations 元素),然后您可以使用 WXCurrentObXML 获取气象站之一的状况。

There are numerous weather APIs out there that will look up the weather based on zip codes, or find the nearest one for a zip code. See this question.

The national weather service has a REST API. CTRL+F for zipcode:

Summarized Data for One or More Zipcodes: Returns DWML-encoded NDFD data for one or more zip codes (50 United States and Puerto Rico).

Here is a sample request


I'm not sure if that one has current conditions. If not, you can use the Wunderground API. First you use GeolookupXML to look up nearby weather stations based on the city (see the nearby_weather_stations element in the sample output), then you can use WXCurrentObXML to get the conditions at one of the weather stations.

北斗星光 2024-09-01 22:42:10

虽然需要进行一些搜索,但 NOAA 维护了所有 METAR 气象站的列表,其中包含它们的纬度和经度坐标,以及指向它们的 RSS 和 XML 提要 URL 的直接链接。该列表以 XML 形式存储在此处: http://www.weather.gov/xml/current_obs /index.xml

您可以使用 Google 或 Yahoo 的地理编码 API 来查找地名的纬度/经度(城市、地址、邮政编码等),然后在气象站列表中搜索距离该地点最近的 METAR 站给定位置。

It took some searching, but NOAA maintains a list of all the METAR weather stations, with their latitude and longitude coordinates, as well as direct links to their RSS and XML feed URLs. The list is stored in XML here: http://www.weather.gov/xml/current_obs/index.xml

You could use Google's or Yahoo's geocoding APIs to lookup the latitude/longitude of a place name (City, Address, Zipcode, etc.) and then search the weather stations list for the closest METAR station to the given location.

彼岸花似海 2024-09-01 22:42:10

我尝试了您的链接,但街道输入了我的邮政编码,而不是城市。它返回了正确的位置和天气预报。它可能只是一个记录不充分的 API,并且用 5 位 zip 替换的城市/街道参数确实可以满足您的要求。

i tried your link and instead of City, Street inputed my zip code. It returned the correct location and weather report. It's possible that it's just a poorly-documented API and a city/street parameter replaced with a 5-digit zip will indeed do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文