ajur-media/openweathermap-data-parser

一个用于解析来自OpenWeatherMap.org的天气数据的PHP类。这个库试图标准化和抽象数据,并消除不一致性

0.99.1 2024-08-23 14:02 UTC

This package is not auto-updated.

Last update: 2024-09-20 14:20:05 UTC


README

一个PHP类,用于从OpenWeatherMap.org检索和解析天气数据。

这个库旨在标准化提供的数据并消除一些不一致性。这个库既不是由OpenWeatherMap维护的,也不是他们的官方PHP API。

安装

这个库可以在Packagist上找到。推荐通过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 — 请参阅与源代码一起分发的LICENSE文件,以获取有关版权和许可的更多信息。

在使用此服务之前,请查看以下官方链接,以了解OpenWeatherMap的条款、定价和许可。