sohelrana820/weather-forecast-php

Dark Sky API (原 Forecast.io) 的 PHP 封装器

1.0.0 2017-02-13 23:32 UTC

This package is auto-updated.

Last update: 2024-09-13 13:41:01 UTC


README

weather-forecast-php 是 Dark Sky API (原 Forecast.io) 的 PHP 封装实现

安装

通过 composer 安装非常简单

composer require sohelrana820/weather-forecast-php

用法

<?php

use SohelRana820\Forecast\Forecast;

$forecast = new Forecast(API_KEY);
$forecast->setLatitude(DEFAULT_LATITUDE);
$forecast->setLongitude(DEFAULT_LATITUDE);
$response = $forecast->request();

// Retrieve the current data
var_dump($response->getCurrentlyData());

// Retrieve the hourly data
var_dump($response->getHourlyData());

// Retrieve the daily data
var_dump($response->getDailyData());

// Retrieve weather flags
var_dump($response->getFlags());

如何设置可选参数。

此库允许设置所有可选参数(lng、units 等)

<?php
$forecast->setOptions($optionsArray = ['units' => 'si']);

您可以将所有可选参数作为数组传递。请参阅所有可选参数的官方文档 官方文档。测试