PHP code example of subdee / lcn-weather-forecast-bundle

1. Go to this page and download the library: Download subdee/lcn-weather-forecast-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

subdee / lcn-weather-forecast-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Lcn\WeatherForecastBundle\LcnWeatherForecastBundle(),
        );

        // ...
    }

    // ...
}

$forecast = $this->container->get('lcn.weather_forecast');

$lat = 53.553521;
$lng = 9.948773;


$forecastForDay = $forecast->getForToday($lat, $lng);
// OR:
$forecastForDay = $forecast->getForDay($lat, $lng, strtotime('tomorrow'));

echo $forecastForDay->getSummary();
echo $forecastForDay->getIcon();
foreach ($forecastForDay->getHours() as $hour => $forecastForHour) {
    echo $forecastForHour->getSummary();
    echo $forecastForHour->getIcon();
    $key = 'temperature'; // $key can be any key from forecast.io api, e.g. time, summary, icon, precipIntensity, precipIntensity, precipProbability, temperature, apparentTemperature, dewPoint, humidity, windSpeed, windBearing, visibility, cloudCover, pressure, ozone
    echo $forecastForHour->get($key, 'fallback default value');
}

$forecastForHour = $forecast->getForCurrentHour($lat, $lng);
// OR:
$forecastForHour = $forecast->getForHour($lat, $lng, strtotime('+ 1 day 3 hours'));

echo $forecastForHour->getSummary();
echo $forecastForHour->getIcon();
$key = 'temperature'; // $key can be any key from forecast.io api, e.g. time, summary, icon, precipIntensity, precipIntensity, precipProbability, temperature, apparentTemperature, dewPoint, humidity, windSpeed, windBearing, visibility, cloudCover, pressure, ozone
echo $forecastForHour->get($key, 'fallback default value');