Cmfcmf\OpenWeatherMap::getWeatherForecast PHP Method

getWeatherForecast() public method

Returns the forecast for the place you specified. DANGER: Might return fewer results than requested due to a bug in the OpenWeatherMap API!
public getWeatherForecast ( array | integer | string $query, string $units = 'imperial', string $lang = 'en', string $appid = '', integer $days = 1 ) : WeatherForecast
$query array | integer | string The place to get weather information for. For possible values see ::getWeather.
$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.
$days integer For how much days you want to get a forecast. Default 1, maximum: 16.
return Cmfcmf\OpenWeatherMap\WeatherForecast
    public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $appid = '', $days = 1)
    {
        if ($days <= 5) {
            $answer = $this->getRawHourlyForecastData($query, $units, $lang, $appid, 'xml');
        } elseif ($days <= 16) {
            $answer = $this->getRawDailyForecastData($query, $units, $lang, $appid, 'xml', $days);
        } else {
            throw new \InvalidArgumentException('Error: forecasts are only available for the next 16 days. $days must be 16 or lower.');
        }
        $xml = $this->parseXML($answer);
        return new WeatherForecast($xml, $units, $days);
    }

Usage Example

コード例 #1
0
 public function testWindMetric()
 {
     $forecast = $this->owm->getWeatherForecast('Moscow', 'metric', 'ru', '', 7);
     $this->assertEquals('Moscow', $forecast->city->name);
     $this->assertEquals('RU', $forecast->city->country);
     $this->assertEquals(524901, $forecast->city->id);
     $this->assertEquals('37.615555', $forecast->city->lon);
     $this->assertEquals('55.75222', $forecast->city->lat);
     $this->assertEquals('03:22:56', $forecast->sun->rise->format("H:i:s"));
     $this->assertEquals('15:50:08', $forecast->sun->set->format("H:i:s"));
     $this->assertEquals(7, iterator_count($forecast));
     $forecast_arr = iterator_to_array($forecast);
     $this->assertEquals('5.41 m/s', $forecast_arr[0]->wind->speed);
     $this->assertEquals('61 ENE', $forecast_arr[1]->wind->direction);
 }
All Usage Examples Of Cmfcmf\OpenWeatherMap::getWeatherForecast