Time for action – calling the weather service

Now that we have the user's location we can pass it to the Underground Weather service to get the user's current weather. We will use JSONP to call the service since the service exists in an external domain. Let's go into the WeatherWidget object and make a few changes.

First we need to change the constructor to take the Weather Underground API key. Since we're writing a generic widget that could go on any page on any site, the developer of the page will need to provide their key:

function WeatherWidget($widget, wuKey)

Next we will change the getWeatherReport() method. It now takes the coordinates of the place we want to get a weather report for. In this case it's the user's position that we got from ...

Get HTML5 Web Application Development By Example Beginner's guide 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.