NOAA 预测和当前天气服务 API 的客户端库

dev-master 2021-01-03 10:28 UTC

This package is auto-updated.

Last update: 2024-09-29 04:44:14 UTC


README

请注意:新的 API 仍在开发中。

用于处理 NOAA API 的 PHP 库。有关 NOAA 文档 的更多信息。

可以检索指定地点或站点的预报。每小时和每天的预报都返回 7 天的数据。

观测数据为最近 5 小时

基本用法 - 指定地点的预报

<?php
include "noaa/autoload.php"; //only needed if not using composer bootstrap
use noaa\util\Cache;
use noaa\Point;
use noaa\NOAA;

$noaa = new NOAA(new Cache);
$point = new Point(43.43, -90.80);
$noaa->setPoint($point);
$hourly = $noaa->getHourlyForecast();
foreach($hourly as $forecast){
    echo $forecast->getStart('D, d M H:i:s') . " Temp:" . $forecast->getTemperature() . "\n";
}

基本用法 - 指定地点的观测

<?php
include "noaa/autoload.php"; //only needed if not using composer bootstrap
use noaa\util\Cache;
use noaa\Point;
use noaa\NOAA;

$noaa = new NOAA(new Cache);
$point = new Point(43.43, -90.80);
$noaa->setPoint($point);
//get a station
echo "Observations recorded at: " . $noaa->getStation()->getName()."\n";
$observations = $noaa->getObservations();
foreach($observations as $observation){
    echo $observation->getTime('D, d M H:i:s') . " Temp:" . $observation->getTemperature() . "\n";
}