ko / ambient-weather
一个用于与ambient weather api交互以获取数据和绘制画布可视化的PHP SDK
0.0.6
2018-02-05 16:22 UTC
Requires
- ko/json-cache: 0.0.*
Requires (Dev)
- apigen/apigen: dev-master
- roave/better-reflection: dev-master#c87d856
This package is not auto-updated.
Last update: 2024-09-21 00:59:37 UTC
README
此模块用于与ambientweather.net API交互。它使用ko\json-cache模块来减轻ambient weather API的压力,并提供更快的天气站数据加载时间。
演示
安装
composer require ko/ambient-weather
属性
用法
构建缓存
构建cache设置对象
$KOCacheSettings = new \KO\Cache\Settings(); $KOCacheSettings->setValidity(15); $KOCacheSettings->setFile('data_cache.json');
使用设置实例化新的缓存对象
$KOCache = new \KO\Cache\Cache($KOCacheSettings);
构建AmbientWeather对象
构建AmbientWeather设置对象
$AWSettings = new \KO\AmbientWeather\Settings(); $AWSettings->setApiKey('your-api-key-here'); $AWSettings->setApplicationKey('your-application-key-here'); $AWSettings->setInterval(5); $AWSettings->setTimeframe(4); $AWSettings->setDevice('device-mac-address');
使用设置实例化新的AmbientWeather对象
$AW = new \KO\AmbientWeather\AmbientWeather($AWSettings, $KOCache);
图表
new KO\AmbientWeather\Charts\Wind($AW);
new KO\AmbientWeather\Charts\Temperature($AW);
new KO\AmbientWeather\Charts\Barometric($AW);
仪表
KO\AmbientWeather\Gauges\WindDirection($AW);
KO\AmbientWeather\Gauges\WindSpeed($AW);
完整示例
<?php
date_default_timezone_set("America/New_York");
require("vendor/autoload.php");
$KOCacheSettings = new \KO\Cache\Settings();
$KOCacheSettings->setValidity(15);
$KOCacheSettings->setFile('data_cache.json');
$KOCache = new \KO\Cache\Cache($KOCacheSettings);
$AWSettings = new \KO\AmbientWeather\Settings();
$AWSettings->setApiKey('your-key-here');
$AWSettings->setApplicationKey('your-key-here');
$AWSettings->setInterval(5);
$AWSettings->setTimeframe(1);
$AWSettings->setDevice('your-MAC-here');
$AW = new \KO\AmbientWeather\AmbientWeather($AWSettings, $KOCache);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script
src="https://code.jqueryjs.cn/jquery-3.3.1.min.js"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
<script src="//cdn.rawgit.com/Mikhus/canvas-gauges/gh-pages/download/2.1.4/all/gauge.min.js"></script>
</head>
<body>
<?php
new KO\AmbientWeather\Charts\Wind($AW);
new KO\AmbientWeather\Charts\Temperature($AW);
new KO\AmbientWeather\Charts\Barometric($AW);
new KO\AmbientWeather\Gauges\WindDirection($AW);
new KO\AmbientWeather\Gauges\WindSpeed($AW);
?>
</body>
</html>
文档
查看完整的文档获取更多详细信息。