【发布时间】:2011-06-29 01:16:05
【问题描述】:
我正在创建有关公园的页面。对于每个公园,都有一个纬度/经度,对于大多数公园,我可以使用 Yahoo 天气 API
但由于某种原因,某些页面会返回如下错误:
无效输入 /forecastrss?w=2347563
在我这样调用 Yahoo 天气 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。查看左侧的天气部分:
【问题讨论】:
标签: php yahoo-api yahoo-weather-api