本文介绍了Yahoo Weather API给出了某些美国经/纬度位置的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建有关公园的页面.每个公园都有纬度/经度,对于大多数公园,我都可以使用Yahoo weather API

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:

无效的输入/forecastrss?w = 2347563

Invalid Input /forecastrss?w=2347563

在我对Yahoo weather API进行这样的调用后:

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?

这是我的代码:

$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:

http://www.comehike.com/outdoors/parks/park.php?park_id = 86

推荐答案

此地理编码调用

http://www.geomojo. org/cgi-bin/reversegeocoder.cgi?long = -121.433098& lat = 40.509312

仅返回加利福尼亚州.

is only returning a state, California.

如果我不得不做出一个疯狂的猜测,我会说天气API需要一个比它更具体的位置.这可能是因为某些公园太偏僻(或最近的城镇如此之小),以致地理编码器找不到要传递的坐标的城市.

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.

这篇关于Yahoo Weather API给出了某些美国经/纬度位置的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 12:47