PHP code example of php-weather / openweathermap

1. Go to this page and download the library: Download php-weather/openweathermap 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/ */

    

php-weather / openweathermap example snippets


$openWeatherMapKey = 'key';

$httpClient = new \Http\Adapter\Guzzle7\Client();
$openweathermap = new \PhpWeather\Provider\OpenWeatherMap\OpenWeatherMap($httpClient, $openWeatherMapKey);

$latitude = 47.873;
$longitude = 8.004;

$currentWeatherQuery = \PhpWeather\Common\WeatherQuery::create($latitude, $longitude);
$currentWeather = $openweathermap->getCurrentWeather($currentWeatherQuery);
shell
composer