This helper interacts with the Google Weather API and nicely displays the current weather conditions as well as a 4 day forecast. It works great right “out of the box” but the display can also be easily adjusted with simple CSS . The download comes with a stylsheets that will style your forecasts exactly like the examples below. If you’d like to use the default styles, simply add weather.css from the stylesheets directory in the download, to your site. It will still work if you dont include a stylesheet, it just wont look as nice.
Current Weather & 4 Day Forecast
The first example is the most basic. Simply add a US zip code and it will return the current weather and a forecast for the next 4 days.
$get_weather->all('98168');

Current Weather Only
Our second example supplies a textual location as opposed to a post code and requests only the current weather conditions.
$get_weather->now('Sydney Australia');

Current conditions without city name
By default the weather will display the city name with the results. To omit the city name, simply set the second argument to false.
$get_weather->now('Sydney Australia', $city=false);

Language & Measurement Unit Parameter
The default language for this plugin is english, and the default unit of measurment is fahrenheit. Because well, that’s what I use. However, if you’d like to change the default there’s two ways you can do it. Let’s we want to get the weather in Barcelona, and we want to return the data in spanish and display the temperature in celsius. To change it for just one instance, you can do this:
echo $get_weather->all('Barcelona Spain', $city=true, 'c', 'es');

Okay, but what if you always need to use a different lanuage and/or unit, if can be annoying to have to specify it every time. If you want to permanently override the default setting, you’ll want to open up weather_plugin.php (or weather_helper.php for the CodeIgniter folks), and find the following lines at the very top:
$this->lang = false; // you can set a default language here $this->unit = false; // set default unit of measurement
Let’s say you want to change the default language to French, and the unit of measurement to celsius. These would be your settings:
$this->lang = 'fr'; // you can set a default language here $this->unit = 'c'; // set default unit of measurement
That’s it. Now the data will be returned in French/celcius by default from now on.
Data Only
The final example allows you to skip the display altogether, and will return a multi-dimensional array with the weather for the requested location. This method allows you to format and display the data in any way you like.
$weather = $get_weather->data('New York');
// Current Conditions
$weather['current']['city'];
$weather['current']['condition'];
$weather['current']['temp_f'];
$weather['current']['temp_c'];
$weather['current']['humidity'];
$weather['current']['icon'];
$weather['current']['wind_condition'];
// Forecast Day 1
$weather['forecast1']['day_of_week'];
$weather['forecast1']['low'];
$weather['forecast1']['high'];
$weather['forecast1']['icon'];
$weather['forecast1']['condition'];
// Forecast Day 2
$weather['forecast2']['day_of_week'];
$weather['forecast2']['low'];
$weather['forecast2']['high'];
$weather['forecast2']['icon'];
$weather['forecast2']['condition'];
// Forecast Day 3
$weather['forecast3']['day_of_week'];
$weather['forecast3']['low'];
$weather['forecast3']['high'];
$weather['forecast3']['icon'];
$weather['forecast3']['condition'];
// Forecast Day 4weather['forecast4']['day_of_week'];
$weather['forecast4']['low'];
$weather['forecast4']['high'];
$weather['forecast4']['icon'];
$weather['forecast4']['condition'];
CURRENT CONDITIONS
City: New York, NY
Condition: Cloudy
Temperature F: 23
Temperature C: -5
Humidity: Humidity: 37%
Icon: http://www.google.com/ig/images/weather/cloudy.gif
Wind Condition: Wind: SW at 6 mph
FORECAST DAY 1
Day of Week: Mon
Low: 17
High: 21
Icon: http://www.google.com/ig/images/weather/chance_of_snow.gif
Condition: Scattered Snow Showers
FORECAST DAY 2
Day of Week: Tue
Low: 29
High: 41
Icon: http://www.google.com/ig/images/weather/snow.gif
Condition: Snow Showers
FORECAST DAY 3
Day of Week: Wed
Low: 29
High: 38
Icon: http://www.google.com/ig/images/weather/rain_snow.gif
Condition: Rain and Snow
FORECAST DAY 4
Day of Week: Thu
Low: 17
High: 34
Icon: http://www.google.com/ig/images/weather/partly_cloudy.gif
Condition: Partly Cloudy
Compatibility
This plugin relies on PHP ’s SimpleXML, so this must be enabled on your server for this plugin to work. But not to worry, it’s enabled by default on all PHP installations, and it’s very unlikely that it would have been disabled by your administrator
Additionally, while there is a language parameter to allow you to retrieve results in multiple languages, the data returned by this plugin is UTF -8 encoded. So if your website uses another encoding, it may not work properly.









248 Purchases
55 Comments