1. Go to this page and download the library: Download meteoflow/laravel 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/ */
meteoflow / laravel example snippets
use MeteoFlow\Laravel\Facades\MeteoFlow;
use MeteoFlow\Location\LocationSlug;
use MeteoFlow\Location\LocationCoords;
use MeteoFlow\Location\Location;
// Get current weather by location slug
$location = new LocationSlug('london-gb');
$weather = MeteoFlow::current($location);
echo $weather->getWeather()->getTemperature(); // 15.5
echo $weather->getWeather()->getDescription(); // "Partly cloudy"
// Get current weather by coordinates
$location = new LocationCoords(51.5074, -0.1278);
$weather = MeteoFlow::current($location);
// Get current weather by IP
$location = Location::fromIp('8.8.8.8');
$weather = MeteoFlow::current($location);
// Get daily forecast
$forecast = MeteoFlow::forecastDaily($location);
foreach ($forecast->getForecasts() as $day) {
echo $day->getDate() . ': ' . $day->getTemperatureMax() . '°C';
}
use MeteoFlow\WeatherClientInterface;
use MeteoFlow\Location\LocationSlug;
class WeatherController extends Controller
{
public function show(WeatherClientInterface $client)
{
$location = new LocationSlug('london-gb');
$weather = $client->current($location);
return view('weather', [
'temperature' => $weather->getWeather()->getTemperature(),
'description' => $weather->getWeather()->getDescription(),
]);
}
}
// List all supported countries
MeteoFlow::countries(): CountriesResponse
// List cities for a country code
MeteoFlow::citiesByCountry(string $countryCode): CitiesResponse
// Search cities by name (limit is optional)
MeteoFlow::searchCities(string $query, ?int $limit = null): CitiesResponse
use MeteoFlow\Laravel\Facades\MeteoFlow;
// List all countries
$response = MeteoFlow::countries();
foreach ($response->countries as $country) {
$country->slug; // e.g. "united-kingdom"
$country->name; // e.g. "United Kingdom"
$country->code; // ISO 3166-1 alpha-2, e.g. "GB"
}
// Cities by country code
$response = MeteoFlow::citiesByCountry('DE');
foreach ($response->cities as $city) {
$city->slug; // e.g. "germany-berlin"
$city->name; // City name
$city->country; // Country name
$city->countryCode; // Country code
$city->region; // Region / state name
$city->lat; // Latitude
$city->lon; // Longitude
$city->timezoneOffset; // UTC offset in minutes
}
// Search cities by name
$response = MeteoFlow::searchCities('Berlin', 5);
foreach ($response->cities as $city) {
// Same fields as above
}
use MeteoFlow\Options\ForecastOptions;
use MeteoFlow\Options\Unit;
$options = ForecastOptions::create()
->setDays(14)
->setUnit(Unit::IMPERIAL)
->setLang('de');
$forecast = MeteoFlow::forecastDaily($location, $options);
use MeteoFlow\Options\AirQualityOptions;
use MeteoFlow\Options\Unit;
$options = AirQualityOptions::create()
->setDays(5)
->setUnit(Unit::METRIC);
$airQuality = MeteoFlow::airQuality($location, $options);
use MeteoFlow\Location\Location;
$location = Location::fromSlug('united-kingdom-london');
$geomagnetic = MeteoFlow::geomagnetic($location);