protected function setUp() { // Load the app configuration $ini = parse_ini_file(__DIR__ . '/ApiKey.ini'); $apiKey = $ini['api_key']; $this->owm = new OpenWeatherMap(); $this->owm->setApiKey($apiKey); }
use Cmfcmf\OpenWeatherMap; use Cmfcmf\OpenWeatherMap\Exception as OWMException; require_once __DIR__ . '/bootstrap.php'; $cli = false; $lf = '<br>'; if (php_sapi_name() === 'cli') { $lf = "\n"; $cli = true; } // Language of data (try your own language here!): $lang = 'de'; // Units (can be 'metric' or 'imperial' [default]): $units = 'metric'; // Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works). $owm = new OpenWeatherMap(); $owm->setApiKey($myApiKey); // Example 1: Get current temperature in Berlin. $weather = $owm->getWeather('Berlin', $units, $lang); echo "EXAMPLE 1{$lf}"; // $weather contains all available weather information for Berlin. // Let's get the temperature: // Returns it as formatted string (using __toString()): echo $weather->temperature; echo $lf; // Returns it as formatted string (using a method): echo $weather->temperature->getFormatted(); echo $lf; // Returns the value only: echo $weather->temperature->getValue(); echo $lf; // Returns the unit only: