PHP code example of programmatordev / openweathermap-php-api
1. Go to this page and download the library: Download programmatordev/openweathermap-php-api 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/ */
programmatordev / openweathermap-php-api example snippets
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);
$current = $api->weather()->current(
latitude: 38.7223,
longitude: -9.1393,
);
echo $current->temperature();
echo $current->temperatureWithUnit();
use ProgrammatorDev\OpenWeatherMap\Enum\Language;
use ProgrammatorDev\OpenWeatherMap\Enum\Units;
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;
$api = new OpenWeatherMap(
apiKey: $_ENV['OPENWEATHERMAP_API_KEY'],
options: [
'units' => Units::METRIC,
'language' => Language::ENGLISH,
],
);
$current = $api
->weather()
->withUnits(Units::IMPERIAL)
->withLanguage(Language::PORTUGUESE)
->current(latitude: 38.7223, longitude: -9.1393);
bash
composer