Recipes
Recipe: Lightning Forecast
This recipe shows how to fetch lightning probability forecasts for a given location.
These recipes are teaching examples — not production code.
- Host: examples use the development host apidev.accuweather.com. Switch to api.accuweather.com for production.
- Production hardening: GZIP compression, caching, retries with exponential backoff, and error handling are not included. See the Best Practices guide.
Scenario
"I want to show users whether lightning is likely near their location in the next 2 hours."
Call the Lightning forecasts endpoint with a latitude and longitude.
Endpoint:
Code
Key response fields
| Field | Type | Description |
|---|---|---|
latitude | Number | Latitude of the requested point |
longitude | Number | Longitude of the requested point |
initDateTime | String | Forecast initialization time in ISO 8601 format |
forecasts[].startDateTime | String | Start of the 10-minute interval in ISO 8601 format |
forecasts[].startEpochTime | Integer | Start of the interval as epoch seconds |
forecasts[].probability | Number | Percentage likelihood of at least one lightning strike during the interval |
Complete code sample
Copy a full, runnable example that fetches the lightning forecast, assesses risk, and flags high-risk intervals.
Next steps
- Real-Time Lightning — see current strikes near a location
- Historical Lightning — analyze past lightning activity
- Lightning Parameters — full API reference
Last modified on