|
@ -13,7 +13,7 @@ class Weather { |
|
|
$data = self::_fetch($lat, $lng, $key); |
|
|
$data = self::_fetch($lat, $lng, $key); |
|
|
if(!$data) return null; |
|
|
if(!$data) return null; |
|
|
|
|
|
|
|
|
if(!property_exists($data, 'weather')) |
|
|
|
|
|
|
|
|
if(!property_exists($data, 'current')) |
|
|
return null; |
|
|
return null; |
|
|
|
|
|
|
|
|
$weather = [ |
|
|
$weather = [ |
|
@ -34,39 +34,37 @@ class Weather { |
|
|
] |
|
|
] |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$sunny = self::_sunny($data->coord->lat, $data->coord->lon); |
|
|
|
|
|
|
|
|
$sunny = self::_sunny($data->lat, $data->lon); |
|
|
|
|
|
|
|
|
$icon_name = self::_icon_name($data->weather[0]->id); |
|
|
|
|
|
|
|
|
$icon_name = self::_icon_name($data->current->weather[0]->id); |
|
|
|
|
|
|
|
|
$weather['sun'] = $sunny; |
|
|
$weather['sun'] = $sunny; |
|
|
|
|
|
|
|
|
$weather['description'] = $data->weather[0]->description; |
|
|
|
|
|
|
|
|
$weather['description'] = $data->current->weather[0]->description; |
|
|
$weather['icon']['name'] = $icon_name; |
|
|
$weather['icon']['name'] = $icon_name; |
|
|
$weather['temp'] = [ |
|
|
$weather['temp'] = [ |
|
|
'num' => (double)$data->main->temp, |
|
|
|
|
|
|
|
|
'num' => (double)$data->current->temp, |
|
|
'unit' => '°F' |
|
|
'unit' => '°F' |
|
|
]; |
|
|
]; |
|
|
$weather['feelslike'] = [ |
|
|
$weather['feelslike'] = [ |
|
|
'num' => (double)$data->main->feels_like, |
|
|
|
|
|
|
|
|
'num' => (double)$data->current->feels_like, |
|
|
'unit' => '°F' |
|
|
'unit' => '°F' |
|
|
]; |
|
|
]; |
|
|
$weather['wind'] = [ |
|
|
$weather['wind'] = [ |
|
|
'num' => $data->wind->speed, |
|
|
|
|
|
|
|
|
'num' => $data->current->wind_speed, |
|
|
'unit' => 'mph' |
|
|
'unit' => 'mph' |
|
|
]; |
|
|
]; |
|
|
$weather['pressure'] = [ |
|
|
$weather['pressure'] = [ |
|
|
'num' => (int)$data->main->pressure, |
|
|
|
|
|
|
|
|
'num' => (int)$data->current->pressure, |
|
|
'unit' => 'mb' |
|
|
'unit' => 'mb' |
|
|
]; |
|
|
]; |
|
|
$weather['humidity'] = [ |
|
|
$weather['humidity'] = [ |
|
|
'num' => round($data->main->humidity), |
|
|
|
|
|
|
|
|
'num' => round($data->current->humidity), |
|
|
'unit' => '%' |
|
|
'unit' => '%' |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
$offset = $data->timezone; |
|
|
|
|
|
|
|
|
|
|
|
$weather['timezone']['name'] = $sunny['timezone']; |
|
|
|
|
|
$weather['timezone']['offset'] = $offset; |
|
|
|
|
|
|
|
|
$weather['timezone']['name'] = $data->timezone; |
|
|
|
|
|
$weather['timezone']['offset'] = $data->timezone_offset; |
|
|
|
|
|
|
|
|
#$weather['raw'] = $current;
|
|
|
#$weather['raw'] = $current;
|
|
|
|
|
|
|
|
@ -81,7 +79,7 @@ class Weather { |
|
|
'appid' => $key, |
|
|
'appid' => $key, |
|
|
]; |
|
|
]; |
|
|
$ch = curl_init(); |
|
|
$ch = curl_init(); |
|
|
curl_setopt($ch, CURLOPT_URL, 'https://api.openweathermap.org/data/2.5/weather?'.http_build_query($params)); |
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, 'https://api.openweathermap.org/data/3.0/onecall?'.http_build_query($params)); |
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
|
|
// curl_setopt($ch, CURLOPT_USERAGENT, '');
|
|
|
// curl_setopt($ch, CURLOPT_USERAGENT, '');
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
|