A PHP class to retrieve and parse weather data from OpenWeatherMap.org.
This library aims to normalise the provided data and remove some inconsistencies. This library is neither maintained by OpenWeatherMap nor their official PHP API.
This library can be found on Packagist. The recommended way to install and use it is through Composer.
composer require ajur-media/openweathermap-data-parser
<?php
use AJUR\OpenWeatherMap;
use AJUR\OpenWeatherMap\Exception as OWMException;
// Must point to composer's autoload file.
require 'vendor/autoload.php';
// Language of data (try your own language here!):
$lang = 'ru';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Create OpenWeatherMap object.
// Don't use caching (take a look into Examples/Cache.php to see how it works).
$owm = new OpenWeatherMap('YOUR-API-KEY');
try {
$weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
} catch(\Exception $e) {
echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
}
echo $weather->temperature;
MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.
Please check out the following official links to read about the terms, pricing and license of OpenWeatherMap before using the service: