getWeatherHistory() public method

Returns the weather history for the place you specified.
public getWeatherHistory ( array | integer | string $query, DateTime $start, integer $endOrCount = 1, string $type = 'hour', string $units = 'imperial', string $lang = 'en', string $appid = '' ) : WeatherHistory
$query array | integer | string The place to get weather information for. For possible values see ::getWeather.
$start DateTime
$endOrCount integer
$type string Can either be 'tick', 'hour' or 'day'.
$units string Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
$lang string The language to use for descriptions, default is 'en'. For possible values see http://openweathermap.org/current#multi.
$appid string Your app id, default ''. See http://openweathermap.org/appid for more details.
return Cmfcmf\OpenWeatherMap\WeatherHistory
コード例 #1
0
<?php

/**
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
 *
 * @license MIT
 *
 * Please see the LICENSE file distributed with this source code for further
 * information regarding copyright and licensing.
 *
 * Please visit the following links to read about the usage policies and the license of
 * OpenWeatherMap before using this class:
 *
 * @see http://www.OpenWeatherMap.org
 * @see http://www.OpenWeatherMap.org/terms
 * @see http://openweathermap.org/appid
 */
use Cmfcmf\OpenWeatherMap;
require_once __DIR__ . '/bootstrap.php';
// Language of data (try your own language here!):
$lang = 'en';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap($myApiKey);
// Example 1: Get hourly weather history between 2014-01-01 and today.
$history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
foreach ($history as $weather) {
    echo 'Average temperature at ' . $weather->time->format('d.m.Y H:i') . ': ' . $weather->temperature . "\n\r<br />";
}
コード例 #2
0
 /**
  * Returns the weather history for the place you specified as an object.
  *
  * @param array|int|string $query The place to get weather information for. For possible values see below.
  * @param \DateTime        $start
  * @param int              $endOrCount
  * @param string           $type
  * @param string           $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
  * @param string           $lang  The language to use for descriptions, default is 'en'. For possible values see below.
  *
  * @return OpenWeatherMap\WeatherForecast
  * @throws OpenWeatherMap\Exception
  */
 public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = null, $lang = null)
 {
     return $this->service->getWeatherHistory($query, $start, $endOrCount, $type, empty($units) ? $this->units : $units, empty($lang) ? $this->lang : $lang, $this->api_key);
 }