Je crée des pages sur les parcs. Pour chaque parc, il y a une latitude/lng et pour la plupart des parcs, je suis en mesure d'utiliser l'API météo YahooYahoo API météo donnant des erreurs pour certains États américains lat/lng
Mais pour une raison quelconque, certaines pages renvoient des erreurs comme ceci:
Invalid Input/forecastrss w? = 2347563
Après un appel que je fais comme ça à l'API météo Yahoo:
http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long=-121.433098&lat=40.509312
Toute idée comment je peux résoudre ce genre d'erreurs?
Voici mon code:
$url = 'http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long='.$lng.'&lat='.$lat;
// Calls the url to get the zip code and woeid
$webpage = file_get_contents($url);
//echo $webpage;
try
{
$xml = new SimpleXMLElement($url, 0, true);
// Gets the woeid to look up the weather in that specific place dynamically.
$woeid= $xml->woeid; // Displays "Text"
$zip = $xml->name; // Displays "Text"
// URL to send to yahoo weather to get weather RSS
$yahoo_url = 'http://weather.yahooapis.com/forecastrss?w='.$woeid;
$xml = file_get_contents($yahoo_url);
$yahoo_response = new SimpleXMLElement($xml , 0, false);
$weather_description = $yahoo_response->channel->item->description;
$splitdata = explode('<a', $weather_description);
echo '<p>'.$splitdata[0].'</p>';
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Voici une url d'un exemple où cela ne fonctionne pas. Voir la section météo sur le côté gauche:
http://www.comehike.com/outdoors/parks/park.php?park_id=86