I thought this post would be useful as a follow on from my last post “Using Google Docs As A Webservice”, where I showed how you can use the ‘publish as ATOM feed’ feature of Google Spreadsheet to read dynamic data from your mobile app using PhoneGap and XUI.
In this installment, I’m adding the ability to present the weather in my mobile app (still using PhoneGap and XUI), building on what we used in the previous post. Let’s have a look:
As the title suggests, Google have an unofficial API for retrieving weather information, that is simply a GET request to an iGoogle URL. The one I’m using for CAPE TOWN is:
As you might , you simply specify your city as the ‘weather’ parameter, eg:
[New York City] http://www.google.co.za/ig/api?weather=New+York+City&hl=en_US
[Tokyo, Japan] http://www.google.co.za/ig/api?weather=Tokyo,Japan&hl=en_US
If you examine the response XML, you’ll notice some things:
– You get the ‘current conditions’, Today’s conditions and the next 3 day forecast.
– The wind speed is returned in MPH.
– The forecast low and high temps are in Fahrenheit
Let’s see some code:
Here, I’ve created 2 functions: loadCurrentWeather() and loadForecastWeather() -> They sound be self explanatory:
Notice that I load the functions when the body loads.
I hope you find this post helpful. If you find any errors or and have tips or crits, I’d love to hear from you!
Thanks for reading! Happy hacking.