我正在创建关于公园的页面。对于每一个公园,有一个纬度/经度和大多数公园,我可以使用雅虎天气API雅虎天气API在某些美国纬度/经度位置给出错误
但由于某些原因,有些页面返回这样的错误:
无效的输入/ forecastrss W' = 2347563
一个电话,我作出这样的雅虎天气API后:
http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long=-121.433098&lat=40.509312
任何想法,我怎么能解决这些类型的错误?
这里是我的代码:
$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";
}
下面是一个例子,这并不工作的URL。看到左侧的天气部分:
http://www.comehike.com/outdoors/parks/park.php?park_id=86