|
|
|
|
|
by davchana
1257 days ago
|
|
I usually use forecase.weather.gov They provide a nice textual weather page, with English, for next 7 or 8 days [1]. But it is tiring to open 3 or 4 bookmarks, so I thought to consume that as json & make a single page html app with ajax requests. Its still in progress, I spent few minutes yesterday. The surprising thing was (I was ready to fetch the html text & parse it, difficult), I simply changed one parameter to JSON & I got json [2]. I didn't find any easy to find documentation about json endpoint. My plan is to have city abbreviations on top in horizontal menu, then each click fetches json, puts it into div below. 1. https://forecast.weather.gov/MapClick.php?lat=37.78&lon=-122... 2. https://forecast.weather.gov/MapClick.php?lat=37.98&lon=-120... |
|
FWIW, they also have a pretty decent API. Its based around zones though, which you'd need to look up. So from that lat and lon, you'd get the zone from:
https://api.weather.gov/points/37.7827,-120.38
Using the zone information, you can get to a forecast:
https://api.weather.gov/gridpoints/STO/72,24/forecast
If you're wanting the current observations, you'd pick a station for that grid such as MOUC1 and go to its observations/latest endpoint:
https://api.weather.gov/stations/MOUC1/observations/latest
The API is in a JSON-LD format so its got a lot of links to related topics in the actual JSON payload. Looking at the JSON can make it somewhat easy to feel out what you need. The documentation is here:
https://www.weather.gov/documentation/services-web-api