Kovaloff / OpenWeatherMap-PHP-Api

A php api to parse weather data (including forecasts now!) from OpenWeatherMap.org.

Home Page:http://www.OpenWeatherMap.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenWeatherMap-PHP-Api

A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.

If you are looking for an implementation for the CMS Zikula, you may want to take a look at cmfcmf/Weather.

For example code and how to use this api, please take a look into Examples_*.php files and run them in your browser.

  • Examples_Current.php Shows how to receive the current weather.
  • Examples_Forecast.php Shows how to receive weather forecasts.
  • Examples_Cache.php Shows how to implement a cache.

Notice: This api is not made by OpenWeatherMap, nor their offical php api.

Example call

<?php
use cmfcmf\OpenWeatherMap;
use cmfcmf\OpenWeatherMap\Exception as OWMException;

// Remove this line if you are using composer.
require('cmfcmf/OpenWeatherMap.php');

// Language of data (try your own language here!):
$lang = 'de';

// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';

// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap();

try {
    $weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
    echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
    echo "<br />\n";
} catch(\Exception $e) {
    echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
    echo "<br />\n";
}

echo $weather->temperature;

License

MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.

Please visit the following links to read about the usage policies and the license of OpenWeatherMap before using this class.

Contribute || Support me

I'm very happy if you open pull requests or issues to help making this API more awesome.

However if you like this and want to support me, you may want to flattr a few coins?

Flattr this git repo

Roadmap

  • Add forecast functionality
  • Tell the guys of OpenWeatherMap.org that you made such an api.

About

A php api to parse weather data (including forecasts now!) from OpenWeatherMap.org.

http://www.OpenWeatherMap.org

License:MIT License