PHP code example of endroid / openweathermap

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

    

endroid / openweathermap example snippets


use Endroid\OpenWeatherMap\Client;

$apiKey = '...';
$client = new Client($apiKey);

// Retrieve the current weather for Breda
$weather = $client->getWeather('Breda,nl');

// Or retrieve the weather using the generic query method
$response = $client->query('weather', ['q' => 'Breda,nl']);
$weather = json_decode($response->getContent());

// You can also retrieve a N days forecast
$forecast = $client->getForecast('Breda,nl', 7);


// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Endroid\OpenWeatherMap\Bundle\EndroidOpenWeatherMapBundle(),
    ];
}


$client = $this->get('endroid.open_weather_map.client');