Fatal error on $owm->getWeather()
dmgallardo opened this issue · 2 comments
Hi Guys,
Im getting an error, when I try to get the current weather.
Im using the version: cmfcmf/openweathermap-php-api v2.1.1
OpenWeatherMap exception: Unknown fatal error: OpenWeatherMap returned the following json object: (Code 0).
My Code:
try {
//debug code.
$owm = new OpenWeatherMap('XXXXXXXX');
$weather = $owm->getWeather('Berlin', 'metric', 'en');
dd($weather);
//real code
$query = [
'lat' => $organization->lat,
'lon' => $organization->lng,
];
//$weather = $owm->getWeather($query, $units, $lang);
//dd($weather);
} catch(OWMException $e) {
dd('OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').');
} catch(\Exception $e) {
dd('General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').');
}
I also tried getting the info by url, and it worked fine:
http://api.openweathermap.org/data/2.5/weather?q=Berlin&units=metric&lang=en&mode=xml&APPID=XXXXXX
Im debugging the code and it seems there is an error here:
public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '')
{
$answer = $this->getRawWeatherData($query, $units, $lang, $appid, 'xml');
$xml = $this->parseXML($answer);
//dd($answer, $xml); //The response here is fine!
return new CurrentWeather($xml, $units); //here it seems to be the problem.
}
PS:
The query by lat/long works ?
$query = [
'lat' => $organization->lat,
'lon' => $organization->lng,
];
//$weather = $owm->getWeather($query, $units, $lang);
Thanks.
Hi Guys,
I tested into a empty project with only this library included and it works fine.
So It seems there is a conflict with some library in my project.
Sorry.
Best Regards
So It seems there is a conflict with some library in my project.
Good to hear it works after all! 👍