-
Include Weather Icons in your app: https://github.com/erikflowers/weather-icons
-
Include the below JSON in your application, for example purposes, lets assume it's a global named
weatherIcons
. -
Make a request to OpenWeatherMap:
req = $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=London,uk&callback=?');
- Inspect the code and pair with the data above.
Note: 7xx and 9xx do not get prefixed w/ day/night
req.then(function(resp) {
var prefix = 'wi wi-';
var code = resp.weather[0].id;
var icon = weatherIcons[code].icon;
// If we are not in the ranges mentioned above, add a day/night prefix.
if (!(code > 699 && code < 800) && !(code > 899 && code < 1000)) {
icon = 'day-' + icon;
}
// Finally tack on the prefix.
icon = prefix + icon;
});
Ok, I finally managed to get everything to work perfectly using weather font and OpenWeatherMap API, I tried using the icons.json file provided here but it didn't work properly for me, I think most are outdated. Anyway I adapted some of the code of @mohamedabusrea, also created a new date with local time if you need to use it. It might be a little contrived but it works.