O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required