Copyright 2017 - Custom text here

Weather APIs

Weather APIs

An overview and comparison

Aiming to develop an app displaying weather data or forecasts raises the question where to get the data from. There is a number of public API available of which some are even free of charge. This article focuses on web services that are free of charge at least for a limited amount of requests which are sufficient for development purposes. 


Compared were (so far) ...

OpenWeather

Yahoo WeatherWetterdaten in Düsseldorf-Bild

acMetwit Weather 

Wunderground

Wetter.com

Wetter-Api.de

My personal motivation for this inquiry was that I set up an iOS/Swift class for which the student's task of developing a weather app seemed perfect for the purpose of learning who to deal with he cocoa touch framework. Such an app includes some basic UI, user input (on a settings screen), user defaults, dealing with asynchronous http requests, working with a map and the location services. Another motivational factor was the Kleckrica 44 app, which is now available for Android and is free of charge. One of the features of this app is to add the current local weather to the image taken. Therefore I was in need for a free or very cheap web service providing current weather information.

 

Open Weather

The API provides its results in XMSL or JSON (or even HTML). Input may be the current geo coordinates or the name of a city or region. The data is updated between every 10 minutes or two hours for the free API. Data itself is made available under CC BY-SA 2.0 which allows for commercial use.

OpenWeatherMap offers its service with four different pricing models or SLAs respectively. The free version is limited to 1200 calls per minute and the data is updated every two hours. More recent data and higher calling volumes will be charge. But even then the monthly charges are way better predictable than the cost per 1000 requests type of model that Yahoo charges. 

They offer the recent weather,  forecasts for 5 days per 3 hours, 16 days per day plus historical weather data and data per weather station. Additionally the offer weather maps. In total, compared to the other offerings in this article, some quite complete offering. 

The weather data can be fetched by geo coordinates, name of city or its post code. Cities and regions can be identified by city-codes similar to other services described below. The data can be fetched for a list of cities within one request, but this type of request is not free of charge.  

The client may choose the output format between XML and JSON (default). The API is multi lingual. Literals such as the weather condition etc can then be directly taken from the web service without being localised within the client. However, custom localisation is still possible as the condition is provided as a condition code as well. Optional units are Fahrenheit, Celsius and Kelvin (default). 

Additionally the API is documented quite well on their web pages (in English). 

Ausserdem ist die API auf der Webseite ausgesprochen gut dokumentiert. (Englisch) 

Example: This is the request and the result for the weather data on Achill Island on the day I wrote this documentation. 

http://api.openweathermap.org/data/2.5/weather?lat=53.9667&lon=-10&appid=MyAPIKey

{
   "coord":{
      "lon":-9.72,
      "lat":53.9
   },
   "weather":[
      {
         "id":800,
         "main":"Clear",
         "description":"Sky is Clear",
         "icon":"01d"
      }
   ],
   "base":"stations",
   "main":{
      "temp":283.499,
      "pressure":1039.19,
      "humidity":96,
      "temp_min":283.499,
      "temp_max":283.499,
      "sea_level":1048.75,
      "grnd_level":1039.19
   },
   "wind":{
      "speed":1.66,
      "deg":97.508
   },
   "clouds":{
      "all":0
   },
   "dt":1443688483,
   "sys":{
      "message":0.0184,
      "country":"IE",
      "sunrise":1443681639,
      "sunset":1443723322
   },
   "id":2961666,
   "name":"Rosturk",
   "cod":200
}

Further Information

Weather Conditions and Icons: http://openweathermap.org/weather-conditions 

Pricing information: http://openweathermap.org/price 

 

Yahoo Weather

For Yahoo Weather there are plenty of tutorials available. The API ist provided as RSS, XML or JSON as requested by the user. 

The issue with yahoo is that there is no way of getting from the geo coordinates directly to the weather data. First you will have to identify the regional code or city code WOEID and then you can fetch the weather for this WOEID. 

Yahoo used to provide a WOEID request for free. This service however has been discontinued and replaced by Yahoo Boss, which is not free anymore. However, non-commercial requests may use this service for up to 2000 requests per day, which is more than sufficient for the use with training classes but may quickly be insufficient for published apps.  

Just to avoid any misunderstandings: The Yahoo's weather API as such is still free of charge, but cannot really be used without WOEID. If your use-case allows for a limited amount of specific WOEID, such as for all locations of a company or for all major cities or for some limited region, then you could determine the related WOEIDS at once within the limits of free usage and re-used these WOEIDs within your app.
If you can use the place name (probably keyed in by the user) as input, then the service is free too. 

 

Detour using yahoo search

To avoid the cost BOSS API a mobile app may use the geo coding service that is included in the iOS or Android SDK to determine the place name(s) related to the user's current location. Those services are free anyway, as they are build-in in the mobile OS. (Limitations may apply to google/Android in the event that the app is commercial. Please refer to Google's documentation if in doubt) 

For getting the place name of the current location you may follow this example for iOS in Objective-C and Cocoa Touch: 

CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"cityname - %@",placemark.locality);
}];

Once you got the place name (e.g. Dortmund) this request https://search.yahoo.com/sugg/gossip/gossip-gl-location/?appid=weather&output=sd1&p2=pt&command=Dortmund 

will result in something like this: 

{  
"q":"Dortmund",
"l":{
"gprid":"klD_92z1SOahI3R9Y.7fAA"
},
"r":[
{
"k":"Dortmund",
"d":"pt:iso=DE&woeid=645458&lon=7.45829&lat=51.5166&s=North Rhine-Westphalia&c=Germany&country_woeid=23424829&n=Dortmund, North Rhine-Westphalia, Germany"
}
]
}
 
 

Now that you got the WOEID for Dortmund 645458 you can request the weather itself.

The URI http://weather.yahooapis.com/forecastrss?w=23424829&u=c will response with a result as follows.  

Therein 23424829 is the woied for Dortmund (see the response above) and c indicates that the result is to be delivered in Celsius. If the &u= parameter is omitted then the default will be Fahrenheit. 

{
"query":{
"count":1,
"created":"2015-09-24T17:28:31Z",
"lang":"de",
"results":{
"channel":{
"title":"Yahoo! Weather - Dortmund, DE",
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Dortmund__DE/*http://weather.yahoo.com/forecast/GMXX0024_f.html",
"description":"Yahoo! Weather for Dortmund, DE",
"language":"en-us",
"lastBuildDate":"Thu, 24 Sep 2015 6:49 pm CEST",
"ttl":"60",
"location":{
"city":"Dortmund",
"country":"Germany",
"region":"NW"
},
"units":{
"distance":"mi",
"pressure":"in",
"speed":"mph",
"temperature":"F"
},
"wind":{
"chill":"61",
"direction":"210",
"speed":"8"
},
"atmosphere":{
"humidity":"63",
"pressure":"30.03",
"rising":"0",
"visibility":"6.21"
},
"astronomy":{
"sunrise":"7:18 am",
"sunset":"7:23 pm"
},
"image":{
"title":"Yahoo! Weather",
"width":"142",
"height":"18",
"link":"http://weather.yahoo.com",
"url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
},
"item":{
"title":"Conditions for Dortmund, DE at 6:49 pm CEST",
"lat":"51.52",
"long":"7.46",
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Dortmund__DE/*http://weather.yahoo.com/forecast/GMXX0024_f.html",
"pubDate":"Thu, 24 Sep 2015 6:49 pm CEST",
"condition":{
"code":"28",
"date":"Thu, 24 Sep 2015 6:49 pm CEST",
"temp":"61",
"text":"Mostly Cloudy"
},
"description":"\n<img src=\"http://l.yimg.com/a/i/us/we/52/28.gif\"/><br />\n<b>Current Conditions:</b><br />\nMostly Cloudy, 61 F<BR />\n<BR /><b>Forecast:</b><BR />\nThu - Cloudy. High: 62 Low: 51<br />\nFri - Partly Cloudy. High: 62 Low: 44<br />\nSat - Partly Cloudy. High: 61 Low: 43<br />\nSun - Sunny. High: 61 Low: 43<br />\nMon - Sunny. High: 62 Low: 43<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Dortmund__DE/*http://weather.yahoo.com/forecast/GMXX0024_f.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n",
"forecast":[
{
"code":"26",
"date":"24 Sep 2015",
"day":"Thu",
"high":"62",
"low":"51",
"text":"Cloudy"
},
{
"code":"32",
"date":"28 Sep 2015",
"day":"Mon",
"high":"62",
"low":"43",
"text":"Sunny"
}
],
"guid":{
"isPermaLink":"false",
"content":"GMXX0024_2015_09_28_7_00_CEST"
}
}
}
}
}
}
(This response contains usually five forecast elements in the related JSON-Array. Just not to blow up this article, I removed four of the forecast elements from the response.)

Further Information Links

https://developer.yahoo.com/boss/geo/

https://developer.yahoo.com/yql/guide/usage_info_limits.html (Limits for Endpoints; Additional Limitations to the Table apply) 

https://developer.yahoo.com/weather/documentation.html (Docs incl. weather condition codes) 

Metwit Weather

When researching for alternatives to Yahoo, Metwit came to my attention. Apparently it does not seem to be available anymore. 

Metwit Links (apparently out of service or out of order) 

http://www.metwit.com 

http://soup.metwit.com/post/47181933854/an-alternative-to-yahoo-weather-api  

Wunderground (weather.com)

This service is free only within limitations that may be sufficient for development phases or educational purposes. The limitations are useless for any kind of productive operations. 

http://www.wunderground.com/weather/api?apiref=3be21450e864dc6e

Further Information

http://www.chrisge.org/blog/2013-03-09/wundergound_api

 

Wetter.com

UPDATE: 11th April 2016 - This service does not seem to be available. Neither the request works for my project's API key nor is the portal available. 

At Wetter.com the search for the weather is separated into two steps, similar to Yahoo. First we will have to request the city code of the location by location (city) name. Apparently there is no chance to search for city codes by geo coordinates. Although it may be error prone but in general you could determine the city code in a two step approach as described above with Yahoo. Like using Yahoo your work- and data flow will include a sequence of three asynchronous requests.

Using the API is free of charge. You are entitled to credit wetter.com by two of the following three actions.  
1. Display "Powered by wetter.com" within your app
2. Link to wetter.com 
3. Show the Wetter.com Logo. 

Get your API Key

Once your registered yourself you create a project within their portal and find the API key for the project. 

Get the place name

If you don't get the place name from your app's context or user input, then you may follow the first instructions above (see Yahoo) to determine the place name next to geo coordinates. 

City-Code ermitteln

When the place name is available you can create the URL that leads to the place and city-code. The url schema (see docs) is made of place name, project name and an MD-5 hash code that is made of the api key and the search criteria (place name). This is an example for Mettmann.

The nature of this schema is that you can actually execute the request below (feel free) without me exposing my api key, neither in this article nor by sending the URI over the web. (Even for https, the URI itself is never encrypted.)  

http://api.wetter.com/location/index/search/Mettmann/project/my-very-own-project/cs/0413c766560897be194720cb02d43f2b

folgende Antwort

<?xml version="1.0" encoding="UTF-8"?>
<search>
<search_string>
<![CDATA[Mettmann]]>
</search_string>
<maxhits>30</maxhits>
<hits>1</hits>
<exact_match>no</exact_match>
<credit>
<!--In order to use the free weather data from wetter.com you HAVE TO display at least two out of three of the following possibilities: text, link, logo-->
<text>Powered by wetter.com</text>
<link>http://www.wetter.com</link>
<logo>Download at http://www.wetter.com/api/downloads/#logos</logo>
</credit>
<result>
<item value="1">
<city_code>DE0006935</city_code>
<plz>40822</plz>
<name>Mettmann</name>
<quarter />
<adm_1_code>DE</adm_1_code>
<adm_2_name>Nordrhein-Westfalen</adm_2_name>
<adm_4_name>Mettmann</adm_4_name>
</item>
</result>
</search>

If you receive more than one result, then you should compare the place names or post codes with the list of places that you got in response to the reverse geo-coding. And then use the one that refers to the place with the highest granularity. Eg. prefer the city over the country. 

Wetter abfragen

Now that we have the city code we can finally fetch the weather data. The following example request

http://api.wetter.com/forecast/weather/city/DE0006935/project/my-very-own-project/cs/4098a47c35b72fb4fdbd5c898e9fa596

will result in something like:

<?xml version="1.0" encoding="UTF-8"?>
<city>
    <city_code>DE0006935</city_code>
    <name>Mettmann</name>
    <url>deutschland/mettmann/DE0006935.html</url>
    <post_code>40822</post_code>
    <credit>
        <!--In order to use the free weather data from wetter.com you HAVE TO display at least two out of three of the following possibilities: text, link, logo-->
        <text>Powered by wetter.com</text>
        <link>http://www.wetter.com</link>
        <logo>Download at http://www.wetter.com/api/downloads/#logos</logo>
    </credit>
    <forecast>
        <date value="2015-10-06">
            <wd>180</wd>
            <w>61</w>
            <tx>19</tx>
            <time value="06:00">
                <wd>180</wd>
                <w>61</w>
                <tx>16</tx>
                <tn>14</tn>
                <p>5</p>
                <ws>12</ws>
                <d>1444111200</d>
                <wd_txt>S</wd_txt>
                <w_txt>leichter Regen</w_txt>
            </time>
            <time value="11:00">
                <wd>180</wd>
                <w>61</w>
                <tx>19</tx>
                <tn>16</tn>
                <p>6</p>
                <ws>14</ws>
                <d>1444129200</d>
                <wd_txt>S</wd_txt>
                <w_txt>leichter Regen</w_txt>
            </time>
            <time value="17:00">
                <wd>135</wd>
                <w>61</w>
                <tx>19</tx>
                <tn>16</tn>
                <p>6</p>
                <ws>12</ws>
                <d>1444150800</d>
                <wd_txt>SO</wd_txt>
                <w_txt>leichter Regen</w_txt>
            </time>
            <time value="23:00">
                <wd>135</wd>
                <w>3</w>
                <tx>16</tx>
                <tn>15</tn>
                <p>6</p>
                <ws>11</ws>
                <d>1444172400</d>
                <wd_txt>SO</wd_txt>
                <w_txt>bedeckt</w_txt>
            </time>
            <d>1444111200</d>
            <tn>14</tn>
            <p>24</p>
            <ws>12</ws>
            <wd_txt>S</wd_txt>
            <w_txt>leichter Regen</w_txt>
        </date>
    </forecast>
</city> 

This XML contains a forecast for which each day is cut into four slices. Besides the weather code ("w") 61 it contains a literal ("w_txt") "leichter Regen" (light rain) the highest and lowest predicted temperature for the slice of the day ("tx", "tn") in °C, the wind direction ("wd") and the wind speed ("ws") in km/h as well as the local time as unix timestamp ("d") and others.  

Further Links

http://www.wetter.com/apps_und_mehr/website/api/dokumentation/

http://api.wetter.com/files/wetter.com_openweather_api.pdf 

Logos (including icons)

Wetter-Api.de

The service is free up to 250 requests per day. 

Weather data is limited to Germany. 

Response in XML only. 

There is a glitch in the portal. On the very day when you register, the limits associated with your API key are immediately used up. You may start issuing request on the very next day. 

Input key is the postcode (or PLZ respectively) of the place for which you request the weather data. Therefore you need to get the postcode from the user, the data context or determine it for your current location. Luckily the reverse geo-coding of the mobile OS Android and iOS is quite reliable when it comes to determining a postcode. 

 

The request http://www.wetter-api.de/wetter-MyKey-85737.xml (with MyKey being replaced by your API key) leads to a request like: 

<?xml version="1.0" encoding="UTF-8"?>
<vorhersage>
<ort>Ismaning</ort>
<aktuell>
<icon>partlycloudy</icon>
<icon_url>http:www.wetter-api.de/wettericon/partlycloudy.gif</icon_url>
<temperatur>12</temperatur>
<feuchtigkeit>54</feuchtigkeit>
<wind>33</wind>
<windrichtung>East</windrichtung>
<druck>1030</druck>
<regen>-99990</regen>
<schnee>0</schnee>
<sicht>3</sicht>
</aktuell>
<vorhersagetage>
<vorhersagetag>
<datum>
<epoche>1443718800</epoche>
<tag>1</tag>
<monat>10</monat>
<jahr>2015</jahr>
<tagdesjahres>273</tagdesjahres>
<stunde>19</stunde>
<min>00</min>
<sec>0</sec>
</datum>
<periode>1</periode>
<hoch>
<celsius>17</celsius>
</hoch>
<tief>
<celsius>3</celsius>
</tief>
<conditions>Heiter</conditions>
<icon>clear</icon>
<icon_url>http:www.wetter-api.de/wettericon/clear.gif</icon_url>
<regenwahrscheinlichkeit>0</regenwahrscheinlichkeit>
<regen>
<mm>0</mm>
</regen>
<schnee>
<cm>0</cm>
</schnee>
<wind>
<kmh>1</kmh>
<dir>O</dir>
</wind>
<feuchtigkeit>5</feuchtigkeit>
</vorhersagetag>
<!--- Hier wurden weitere Vorhersagetage ausgeblendet -->
</vorhersagetage>
<warnung>
<warnungvor />
<warnstufe />
<![CDATA[<warninfo></warninfo>]]>
</warnung>
</vorhersage>

(The real response contains nine forecasts. Eight of which have been omitted by the author just to protect the article from being blown up by wallpapers of XML.)

Further Links

http://www.wetter-api.de

Fonts and Icon-Collections

Now that you fetched the weather data and extracted it from the JSON or XML data stream, you will have to display it somehow to the user. For that purpose I found a number of resources for fonts and icons. 

Metwit (out of service) tbd
Lukas Bischoff Lukas Bischoff offers his Font on archill.de free of charge to non-commercial projects.   artill.de
wetter.com (out of service) wetter.com (docs in German)
Eric Flowers  222 Icons around weather as Font GitHub
Daniel Vierich Collection of 60 simple weather icons, which are made available like open source.   http://www.danvierich.de
Mike Afford Fonts and icon collections that are not free but affordable.  Mike Afford Media
Meteocons Free collection of graphics in various formats.  http://www.alessioatzeni.com

 

 

f t g m