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
コード例 #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);
 }
コード例 #2
0
ファイル: home.php プロジェクト: BIGjuevos/pi-hud
$app->get('/', function () use($app) {
    $view = [];
    // NEWS SLIDE
    Feed::$cacheExpire = "30 minutes";
    Feed::$cacheDir = "/tmp";
    $rss_npr = Feed::loadRss("http://www.npr.org/rss/rss.php?id=1001");
    $rss_techmeme = Feed::loadRss("http://www.techmeme.com/feed.xml");
    $view['news_npr'] = $rss_npr->item;
    $view['news_techmeme'] = $rss_techmeme->item;
    // WEATHER SLIDE
    $lang = 'en';
    $units = 'imperial';
    $owm = new OpenWeatherMap(null, new WeatherCache(), 60);
    try {
        $weather = $owm->getWeather('Milpitas', $units, $lang, "06b7f9678c0512b3b8ca9e94758a9601");
        $rawForecast = $owm->getWeatherForecast("Milpitas", $units, $lang, "06b7f9678c0512b3b8ca9e94758a9601", 3);
        $forecast = [];
        while ($rawForecast->valid()) {
            $chunk = $rawForecast->current();
            $forecast[] = ['start' => $chunk->time->from->getTimestamp() - 3600 * 8, 'low' => $chunk->temperature->min->getValue(), 'avg' => $chunk->temperature->now->getValue(), 'max' => $chunk->temperature->max->getValue(), 'pressure' => $chunk->pressure->getValue(), 'precipitation' => $chunk->precipitation->getValue(), 'humidity' => $chunk->humidity->getValue(), 'clouds' => $chunk->clouds->getValue()];
            $rawForecast->next();
        }
        $forecastAvg = [];
        $forecastLow = [];
        $forecastHigh = [];
        $forecastPrecip = [];
        $fp = 0.5;
        foreach ($forecast as $f) {
            $forecastAvg[] = [$f['start'] * 1000, $f['avg']];
            $forecastLow[] = [$f['start'] * 1000, $f['low']];
            $forecastHigh[] = [$f['start'] * 1000, $f['max']];
コード例 #3
0
if (file_exists('../vendor/autoload.php')) {
    // Library is not part of a project. "composer install" was executed directly on this library's composer file.
    require '../vendor/autoload.php';
} else {
    // Library is part of a project.
    /** @noinspection PhpIncludeInspection */
    require '../../../autoload.php';
}
// Language of data (try your own language here!):
$lang = 'de';
// 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();
// Example 1: Get forecast for the next 10 days for Berlin.
$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 10);
echo "EXAMPLE 1<hr />\n\n\n";
echo "City: " . $forecast->city->name;
echo "<br />\n";
echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i');
echo "<br />\n";
echo "<br />\n";
foreach ($forecast as $weather) {
    // Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object.
    // Take a look into 'Examples_Current.php' to see the available options.
    echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i');
    echo "<br />\n";
    echo $weather->temperature;
    echo "<br />\n";
    echo "---";
    echo "<br />\n";
コード例 #4
0
 /**
  * Returns the current weather at 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 int              $days  For how much days you want to get a forecast. Default 1, maximum: 14.
  * @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 getWeatherForecast($query, $days = 1, $units = null, $lang = null)
 {
     return $this->service->getWeatherForecast($query, empty($units) ? $this->units : $units, empty($lang) ? $this->lang : $lang, $this->api_key, $days);
 }