Guest author Kurt Collins is a developer evangelist for Built.io.
I fell in love in 2012. With an app. And I’m not ashamed to admit it.
I considered weather apps mere utilities, not something I should expend energy falling in love with. And then came Dark Sky by Forecast.io. The Dark Sky app is the perfect example of what an app should be. It does one job, and it does it well. It gives me extremely accurate predictions on when there’s going to be precipitation. If you’re not using it, then you’re missing out.
When you see an app like Dark Sky, you have to wonder, how did they make that? The folks at Forecast.io have an answer for that, too: They’ve released the Dark Sky API, so anyone can put the same weather features into their apps.
Clear Skies For Developers
The Dark Sky API, like its namesake app, is simple and easy to use. You can register for a developer account with an email address and get a free API key. You can make 1,000 API calls per day. After that, you pay $0.0001 per call.
There are two main API endpoints:
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME
With the first endpoint, all you have to do is make a call with the longitude and latitude of a given location. The API will return an hourly forecast (for the next 48 hours), a daily forecast (for 7 days), and a minute-by-minute forecast (for 1 hour, where available). With one simple API call you can have an up-to-the-minute forecast of the weather to use for whatever purpose you dream up. Imagine, for example, a travel app
that detects the weather at your destination and, if it’s raining, orders a car service to meet you at the airport.
The second endpoint is even more interesting, though. Using it, you can retrieve the weather as far as 60 years in the past or a forecast for up to 10 years in the future (where available). I obviously question the accuracy of a weather prediction 10 years in the future, but it sure is fun to play with. The last variable, TIME, is passed in either using Unix time or a formatted date/time string.
There are two important options you should know about when using this API. When using the TIME variable, you have the option of specifying timezones. The API has some sanity defaults and will automatically assume you’re referring to the timezone of the location you’ve submitted.
Another important option is the capability to pass along a callback and return the API response as JSONP. JSONP allows you to make calls from Web browsers and return data from an API to JavaScript directly. JSONP is an end-run around the security policy most browsers have in place that states a script can only access data from other scripts and Web pages on the same domain.
Use this feature with caution as it involves taking some calculated risks with security. But it will make your life easier if you’re just coding something quickly in JavaScript.
Good Weather For The Internet Of Things
There are certain types of data that are going to be fundamental in a world taken over by the Internet of Things. Weather data is one of those fundamentals. Your self-driving convertible car will need to predict the weather to close up the roof and roll up the windows before it starts raining—and also avoid streets that have a tendency to flood. Your connected thermostat will want to have some kind of weather feed in order to know what an optimal indoor temperature will be for that day. Your connected light bulbs should not only know when the sun rises and sets, but it should also know when it’s cloudy and overcast outside.
Dark Sky has brought simplicity to the world of weather prediction. More importantly, it’s brought granularity. The fact that they expose the weather forecast down to the minute with such simplicity is precisely what connected devices will need in the very near future.
Photo by betancourt
Editor’s note: While Built.io is currently a sponsor of ReadWrite’s Code section, Collins submitted this post independently through ReadWrite’s established guest-post program. Editorial is separate from advertising.