12.1. Creating a Weather Widget
Weather information is popular to display both on the desktop and on the Web. Many applications and widgets are solely devoted to retrieving and displaying this information. Since weather changes constantly, Ajax is well suited to this type of widget.
12.1.1. The Weather.com SDK
The first step in creating this widget is to locate a source of weather information. Probably the most popular is the Weather.com XML weather service. The use of the Weather.com XML service hinges upon following their guidelines. To use their XML feeds, you must first register for a license at http://registration.weather.com/registration/xmloap/step1. After you register, Weather.com sends an e-mail with a link to the XML feed SDK and provides you with a license key and partner ID.
For web-based applications, like this widget, you must limit how often you retrieve information from the service. As specified in the SDK documentation, the refresh rate for the Current Conditions information is 30 minutes; therefore, the server application must cache the retrieved weather information and only refresh the information every 30 minutes. There are two ways to accomplish this:
Create a smart thread that runs independently of the web application and pulls the feed every 30 minutes. The application then solely uses the cached feed and never worries about the time span between information pulls.
With every page request, the application can keep track of the last time the feed was retrieved ...
Get Professional Ajax, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.