Skip to content

Weather

by Colin on June 23rd, 2009

If you haven't noticed where the web is going, everything is all about the now. With Twitter, Facebook, MySpace (anyone still use myspace anymore?), blogging, and others, the web is directing itself more towards small statements to announce what you're doing now. A thing that's nice to display on your website (or you may even need for a client) is to display the weather.

Yahoo Web API's have some nice classes, including a handy class that deals with weather.  Here you can see a quick example I made to display the weather using Fahrenheit in your zip code.  The documentation that they give may be a bit confusing at first, but after 20 min or so of testing you'll see that this API is quite nice!

  1. package {
  2.  
  3. import com.yahoo.webapis.weather.CurrentConditions;
  4. import com.yahoo.webapis.weather.Weather;
  5. import com.yahoo.webapis.weather.WeatherService;
  6. import com.yahoo.webapis.weather.events.*;
  7.  
  8. import flash.display.Sprite;
  9.  
  10. public class WeatherTest extends Sprite
  11. {
  12.  
  13. public var ws:WeatherService;
  14.  
  15. public const zip:String = "ENTER YOUR ZIP HERE";
  16.  public function WeatherTest() : void
  17. {
  18.  
  19. ws = new WeatherService ();
  20. ws.getWeather(zip, "f");
  21.  
  22. ws.addEventListener(WeatherResultEvent.WEATHER_LOADED, weatherLoaded, false, 0, true);
  23. ws.addEventListener(WeatherErrorEvent.INVALID_LOCATION, weatherError, false, 0, true);
  24.  
  25. }
  26.  
  27. private function weatherLoaded (e:WeatherResultEvent) : void {
  28. trace ("HUMIDITY: " + ws.weather.current.atmosphere.humidity);
  29. trace ("CODE: " + ws.weather.current.code);
  30. trace ("TEMPERATURE: " + ws.weather.current.temperature);
  31. trace ("WIND SPEED: " + ws.weather.current.wind.speed);
  32. }
  33.  
  34. private function weatherError (e:WeatherErrorEvent) : void { trace (e.toString ()); }
  35. }
  36. }

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS