I am creating pages about parks. For each park, there is a lat/lng and for most parks, I am able to use the Yahoo weather API
But for some reason, some pages return errors like this:
Invalid Input /forecastrss?w=2347563
After a call that I make like this to the Yahoo weather API:
http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long=-121.433098&lat=40.509312
Any idea how I can resolve these sorts of errors?
Here is my 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";
}
Here is a url of an example where this doesn't work. See the weather section on the left side:
This geocoding call
http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long=-121.433098&lat=40.509312
is only returning a state, California.
If I had to make a wild guess, I'd say the weather API needs a more specific location than that. This may be because some parks are so remote (or the nearest town so small) that the geocoder can't find a city for the coordinates you're passing.