Skip to content

hoerbi1000/google-weather-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Weather API

Google Weather API is a PHP based library for retrieving and displaying weather at any location, utilizing Google's weather API.

Live examples

Quick start

Clone the repo, git clone git://github.com/Geczy/google-weather-api.git, or download the latest release.

<?php
include_once('classes/google_weather.class.php');

$googleWeather = new \Geczy\Weather\GoogleWeatherAPI();
$weatherData = $googleWeather->getWeather('Los Angeles');

/* Your view file that formats the array response $weatherData. */
include('views/example1.php');

Customizing

You can display multiple weather data on one page, in different languages, degrees, etc. Start by setting your defaults, and then using the functions provided to display multiple versions of weather.

Overriding defaults

Simply instantiate GoogleWeatherAPI with your own variables to override the defaults. For example:

<?php
$defaults = array(
	'degree'   => 'c',
	'language' => 'fr',
);

$googleWeather = new \Geczy\Weather\GoogleWeatherAPI($defaults);

Retrieve a location

<?php
$googleWeather->getWeather('Paris');

Retrieve in Celsius or Fahrenheit

<?php
$googleWeather->setDegree('c'); // 'c' or 'f'
$googleWeather->getWeather('Paris');

Set a language

<?php
$googleWeather->setLanguage('fr');
$googleWeather->getWeather('Paris');

Custom weather icons

Icon sets included are:

  • Google
  • Dotvoid
  • KWeather
  • NYTimes
  • Yahoo

See a suggestion in views/example1.php for using these icons.

Example response

Here's an example of what getWeather() will return:

<?php
array (size=3)
  'info' =>
	array (size=3)
	  'city' => string 'Los Angeles, CA' (length=15)
	  'zip' => string 'Los+Angeles' (length=11)
	  'unit' => string 'US' (length=2)
  'current' =>
	array (size=5)
	  'condition' => string 'Cloudy' (length=6)
	  'temp_f' => string '66' (length=2)
	  'humidity' => string 'Humidity: 73%' (length=13)
	  'icon' => string 'cloudy.gif' (length=94)
	  'wind_condition' => string 'Wind: N at 0 mph' (length=16)
  'forecast' =>
	array (size=4)
	  'Sun' =>
		array (size=4)
		  'low' => string '63' (length=2)
		  'high' => string '79' (length=2)
		  'icon' => string 'mostly_sunny.gif' (length=100)
		  'condition' => string 'Mostly Sunny' (length=12)
	  'Mon' =>
		array (size=4)
		  'low' => string '64' (length=2)
		  'high' => string '81' (length=2)
		  'icon' => string 'sunny.gif' (length=93)
		  'condition' => string 'Clear' (length=5)
	  'Tue' =>
		array (size=4)
		  'low' => string '64' (length=2)
		  'high' => string '84' (length=2)
		  'icon' => string 'mostly_sunny.gif' (length=100)
		  'condition' => string 'Mostly Sunny' (length=12)
	  'Wed' =>
		array (size=4)
		  'low' => string '64' (length=2)
		  'high' => string '82' (length=2)
		  'icon' => string 'sunny.gif' (length=93)
		  'condition' => string 'Clear' (length=5)

Bug tracker

Have a bug? Please create an issue here on GitHub!

https://github.com/Geczy/google-weather-api/issues

Copyright and License

Copyright 2012 Matthew Gates

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Weather using Google's API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%