A javascript library for customised requests to the Forecast.io weather API. For a documentation of the API refer to Forecast.io.
Forecast ( apikey )
Creates a new Forecast object that manages your API key.
Forecast.getForecast ( lat, long, callback, options )
Send a request to the Forecast.io servers.
latThe latitude for the forecastlongThe longitude for the forecastcallback( Forecast.Response )The callback to be invoked when a response is receivedoptionsAn object with options to customise the request:
Options
timeThe time for the forecastunitsThe unit of the forecastexcludeComma separated String or Array of fields to exclude from the responseextendFlag if the extend parameter should be appended to the requestnocacheTry to prevent the browser from caching request results. This not part of the Forecast API and might not work for all browsers.
Forecast.Response
An object containing all data of a Forecast request.
- The
hourly, dailyandminutelyproperties containData.Blockobjects. - The
flagsproperty contains aData.Flagsobject.
Forecast.Data.Block
An array containing Data.Point objects. The array has the additional properties summary and icon.
Forecast.Data.Point
An object with all the properties described in the Forecast.io Docs (e.g. temperature, humidity, windspeed etc.).
Forecast.Data.Flags
Contains all properties described in the documentation. Properties with hyphen are camel-cased for easier access:
darkskyUnavailable instead of darksky-unavailable
Usage
var lat, long;
...
var f = new Forecast("your api key");
f.getForecast(lat, long, updateWeather, { units: 'si', nocache: true, exclude: ['hourly', 'flags'] });
function updateWeather(forecast) {
var today = forecast.daily[0];
var div = document.getElementById('weather');
div.innerHTML = '<span>' + today.temperatureMax + '°</span>';
var summary = document.getElementById('summary');
summary.innerText = forecast.daily.summary;
}