2011-06-29 6 views
0

私は公園に関するページを作成しています。各公園について、緯度/経度があり、ほとんどの公園のために、私はYahooの天気予報APIYahoo天気の特定の米国緯度/経度の場所でエラーが発生する

を使用することができていますが、何らかの理由で、一部のページが、このようなエラーを返す:

無効な入力/ forecastrssのw? =私はYahooの天気APIに次のように作るコールの後に2347563

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

答えて

1

このジオコーディングコール

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

のみ、カリフォルニア州の状態を返しています。

私が野生の推測をしなければならない場合、天気APIにはそれよりも具体的な場所が必要だと言えます。これは、ジオコーダーがあなたが通過している座標の都市を見つけることができないほど離れた公園(または最も小さい町の中で最も小さい町)があるためです。

2

Yahooからの緯度経度と天気の両方の呼び出しを行うと、より良い結果が得られる場合があります。 YQLを使用して、両方の呼び出しを行うことができます。例えば

は、上記のあなたの緯度/経度のペアを使用して、ここで最初のWOEIDに緯度/経度のペアに変換YQLクエリーは、予測を取得することを使用して、です:

select * from weather.woeid where w in (select woeid from geo.placefinder where text="-121.433098, 40.509312" and gflags="R")

しようとしたときYQLコンソールの結果は次のとおりです。


<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" 
    yahoo:count="1" yahoo:created="2011-12-30T20:43:08Z" yahoo:lang="en-US"> 
    <results> 
     <rss version="2.0" 
      xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"> 
      <channel> 
       <title>Yahoo! Weather - Old Station, CA</title> 
       <link>http://us.rd.yahoo.com/dailynews/rss/weather/Old_Station__CA/*http://weather.yahoo.com/forecast/USCA0801_f.html</link> 
       <description>Yahoo! Weather for Old Station, CA</description> 
       <language>en-us</language> 
       <lastBuildDate>Fri, 30 Dec 2011 11:53 am PST</lastBuildDate> 
       <ttl>60</ttl> 
       <yweather:location city="Old Station" 
        country="United States" region="CA"/> 
       <yweather:units distance="mi" pressure="in" speed="mph" temperature="F"/> 
       <yweather:wind chill="51" direction="200" speed="7"/> 
       <yweather:atmosphere humidity="89" pressure="30.08" 
        rising="2" visibility="4"/> 
       <yweather:astronomy sunrise="7:33 am" sunset="4:52 pm"/> 
       <image> 
        <title>Yahoo! Weather</title> 
        <width>142</width> 
        <height>18</height> 
        <link>http://weather.yahoo.com</link> 
        <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url> 
       </image> 
       <item> 
        <title>Conditions for Old Station, CA at 11:53 am PST</title> 
        <geo:lat>40.59</geo:lat> 
        <geo:long>-121.49</geo:long> 
        <link>http://us.rd.yahoo.com/dailynews/rss/weather/Old_Station__CA/*http://weather.yahoo.com/forecast/USCA0801_f.html</link> 
        <pubDate>Fri, 30 Dec 2011 11:53 am PST</pubDate> 
        <yweather:condition code="26" 
         date="Fri, 30 Dec 2011 11:53 am PST" temp="51" text="Cloudy"/> 
        <description><![CDATA[ 
<img src="http://l.yimg.com/a/i/us/we/52/26.gif"/><br /> 
<b>Current Conditions:</b><br /> 
Cloudy, 51 F<BR /> 
<BR /><b>Forecast:</b><BR /> 
Fri - Rain/Snow Showers. High: 43 Low: 21<br /> 
Sat - Partly Cloudy. High: 48 Low: 23<br /> 
<br /> 
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Old_Station__CA/*http://weather.yahoo.com/forecast/USCA0801_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> 
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/> 
]]></description> 
        <yweather:forecast code="5" date="30 Dec 2011" 
         day="Fri" high="43" low="21" text="Rain/Snow Showers"/> 
        <yweather:forecast code="30" date="31 Dec 2011" 
         day="Sat" high="48" low="23" text="Partly Cloudy"/> 
        <guid isPermaLink="false">USCA0801_2011_12_31_7_00_PST</guid> 
       </item> 
      </channel> 
     </rss> 
    </results> 
</query>
関連する問題