Cmfcmf\OpenWeatherMap::getWeather PHP Method

getWeather() public method

Returns the current weather at the place you specified.
public getWeather ( array | integer | string $query, string $units = 'imperial', string $lang = 'en', string $appid = '' ) : CurrentWeather
$query array | integer | string The place to get weather information for. For possible values see below.
$units string Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
$lang string The language to use for descriptions, default is 'en'. For possible values see http://openweathermap.org/current#multi.
$appid string Your app id, default ''. See http://openweathermap.org/appid for more details.
return Cmfcmf\OpenWeatherMap\CurrentWeather The weather object. There are three ways to specify the place to get weather information for: - Use the city name: $query must be a string containing the city name. - Use the city id: $query must be an integer containing the city id. - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
    public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '')
    {
        $answer = $this->getRawWeatherData($query, $units, $lang, $appid, 'xml');
        $xml = $this->parseXML($answer);
        return new CurrentWeather($xml, $units);
    }

Usage Example

コード例 #1
0
 public function testUnauthorizedAccess()
 {
     try {
         $this->owm->getWeather('Paris');
     } catch (OWMException $e) {
         $this->assertEquals(401, $e->getCode());
         $this->assertRegExp('/^Invalid API key/', $e->getMessage());
     }
 }
All Usage Examples Of Cmfcmf\OpenWeatherMap::getWeather