Skip to content

siFeiden/ForecastIO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Forecast.io.js

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.

  • lat The latitude for the forecast
  • long The longitude for the forecast
  • callback( Forecast.Response ) The callback to be invoked when a response is received
  • options An object with options to customise the request:

Options

  • time The time for the forecast
  • units The unit of the forecast
  • exclude Comma separated String or Array of fields to exclude from the response
  • extend Flag if the extend parameter should be appended to the request
  • nocache Try 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, daily and minutely properties contain Data.Block objects.
  • The flags property contains a Data.Flags object.

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 + '&deg;</span>';

    var summary = document.getElementById('summary');
    summary.innerText = forecast.daily.summary;
}

About

A javascript library for the Forecast.io weather API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published