PHP code example of rawaby88 / open-weather-laravel
1. Go to this page and download the library: Download rawaby88/open-weather-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/ */
rawaby88 / open-weather-laravel example snippets
use Rawaby88\OpenWeatherMap\Services\CWByCityName;
$cw = (new CWByCityName('London'))->get();
/**
* With ISO 3166 country codes
* $cw = (new CWByCityName('Warsaw', 'pl'))->get();
*/
use Rawaby88\OpenWeatherMap\Services\CWByCityId;
$cw = (new CWByCityId(2172797))->get();
use Rawaby88\OpenWeatherMap\Services\CWByZipCode;
$cw = (new CWByZipCode(94040, 'us'))->get();
use Rawaby88\OpenWeatherMap\Services\CWByCoordinates;
// CWByCoordinates(latitude, longitude)
$cw = (new CWByCoordinates(35, 139))->get();
use Rawaby88\OpenWeatherMap\Services\CWByCityName;
$cw = (new CWByCityName('London'))->get();
/**
* With ISO 3166 country codes
* $cw = (new CWByCityName('Warsaw', 'pl'))->get();
*/
$temperature = $cw->temperature; // return Temperature object
$weather = $cw->weather; // return Weather object
$location = $cw->location; // return Location object
$sun = $cw->sun; // return Sun object
/**
* Each one of [temperature, weather, location, sun]
* can be encoded to json by calling toJson();
*/
$temperature->toJson();
$weather->toJson();
$location->toJson();
$sun->toJson();
use Rawaby88\OpenWeatherMap\Services\CWByRectangleZone;
//CWByRectangleZone(lon-left,lat-bottom,lon-right,lat-top,zoom)
$cw = (new CWByRectangleZone(12,32,15,37,10))->get();
use Rawaby88\OpenWeatherMap\Services\CWByCitiesInCircle;
//CWByCitiesInCircle(latitude, longitude, number_of cities_to_return)
$cw = (new CWByCitiesInCircle(55.5, 37.5, 10))->get();
use Rawaby88\OpenWeatherMap\Services\CWByCitiesInCircle;
$cw = (new CWByCitiesInCircle(55.5, 37.5, 10))->get();
//to loop through cities result
foreach ($cw->list as $city)
{
$temperature = $city->temperature; // return Temperature object
$weather = $city->weather; // return Weather object
$location = $city->location; // return Location object
$sun = $city->sun; // return Sun object
}
//get specific city with index
$city1 = $cw->index(2);
//get cities count in the list
$city1 = $cw->count();
//get the first city in the list
$city1 = $cw->first();
use Rawaby88\OpenWeatherMap\Services\CWByCityName;
$cw = (new CWByCityName('London'))->get();
$temperature = $cw->temperature;
$temperature->temp; //return current temperature
$temperature->feelsLike; //return feels like
$temperature->tempMax; //return max temperature
$temperature->tempMin; //return min temperature
$temperature->pressure; //return pressure
$temperature->humidity; //return humidity
/**
* toJson()
* {"temp":9,"feelsLike":4,"tempMax":10,"tempMin":9,"pressure":1000,"humidity":53}
*/
$temperature->toJson();
use Rawaby88\OpenWeatherMap\Services\CWByCityName;
$cw = (new CWByCityName('London'))->get();
$location = $cw->location;
$location->city; //return city name
$location->countryCode; //return ISO country code
$location->lon; //return longitude coordinate
$location->lat; //return latitude coordinate
/**
* toJson()
* {"city":"Warsaw","countryCode":"PL","lon":21.0118,"lat":52.2298}
*/
$location->toJson();
use Rawaby88\OpenWeatherMap\Services\CWByCityName;
$cw = new CWByCityName('London');
/**
* You can change the unit type before making the call.
* The default value will be called from config file if there was no changes.
*/
$cw->setUnitType('imperial');
/**
* You can also change the language before making the call
* The default value will be called from config file if there was no changes.
*/
$cw->setLanguage('pl');
$cw->volUnit; // rain and snow volume unit | mm
$cw->presUnit; // pressure unit | hPa
$cw->distUnit; //Distance unit meter/sec | miles/hour
$cw->tempUnit; //Temperature unit Kelvin | Celsius | Fahrenheit.
$cw->get();