Google非公式天気予報API [Google Weather API] TEST

class googleWeatherApi

www.xxxx.net/googleWeatherApi/googleWeatherApi_class.php


表示させたい都市名を入力


$googleWeatherApi_class->jsApi()

javascript形式で成形したHTMLを返す

<script type="text/javascript" src="googleWeatherApi.js"></script> <script type="text/javascript"> p1 = ''; p2 = ''; hl = ''; html = ''; googleWeatherApi(p1,p2,hl,html); </script>

$googleWeatherApi_class->getHtml( $p1:string , $p2:string , $hl:string , $html:string )

デフォルトテンプレートを選択し成形したHTMLを返す

引数内容型初期値サンプル
$p1 都市名 stringNULLsapporo、札幌、札幌市
$p2 地域名 stringNULLhokkaido、北海道
$hl 国コード(言語)stringNULLjp
$htmlhtmlテンプレート選択stringNULLNull or 'simple' or 'today'
戻り値内容
html成形済みHTMLソース

$googleWeatherApi_class->attach( $p1:string , $p2:string , $hl:string , $html:string )

$htmlをテンプレートとし配列をアタッチしHTMLへ成形

引数内容型初期値サンプル
$p1 都市名 stringNULLsapporo、札幌、札幌市
$p2 地域名 stringNULLhokkaido、北海道
$hl 国コード(言語)stringNULLjp
$htmlhtmlテンプレートstringNULLHTML(アタッチ方法は以下を参照)
戻り値内容
html成形済みHTMLソース
値アタッチ方法
{{ 配列の頭文字2文字 / 項目名 }}
例){{cc/condition}} => にわか雨
forecast_conditions の場合、{{ 配列の頭文字2文字fc : 配列番号 / 項目名 }}
例){{fc:3/month}} => 9

※値は以下、googleWeatherApi_class の 戻りobject の詳細参照

[ テンプレートのCSSサンプル ]

/*weather*/ html * #weather * {margin:0; padding:0; border:0;} #weather {width:190px; border:1px solid #00CCFF; float:left; font-size:100%;} #weather .header {margin:4px; padding:0 2px; border-bottom:1px dashed #999999;} #weather .bodyer {margin:4px;} #weather .footer {margin:8px 0 4px 4px; clear:both; font-size:70%;} #weather h3 {font-size:100%; font-weight:bold; margin:0;} #weather h3 span {font-size:100%;} #weather .image {float:left; width:50px; text-align:center; font-size:90%; font-weight:bold;} #weather .image img {margin:2px;} #weather .condition {float:left; margin:0 5px 0 10px;} #weather h5 {font-size:250%; margin:0} #weather h5 span {font-size:40%;} #weather p {color:#666666; margin:0; font-size:80%;} #weather ul {margin:0; padding:0;} #weather li {list-style-type:none; float:left; width:60px; text-align:center;} #weather span.low {color:#3333FF;} #weather span.high{color:#CC3300;}

[ テンプレートのHTMLサンプル ] (改行コードは含めないでください)

<div id="weather"> <div class="header"> <h3>{{fi/postal_code2}}{{fi/postal_code1}} <span>{{fi/month}}/{{fi/day}}</span></h3> </div> <div class="bodyer"> <div class="image"> {{cc/img_tag}}<br /> {{cc/condition}} </div> <div class="condition"> <h5>{{cc/temp_c}}<span>&#08451;</span></h5> <p>{{cc/humidity}}<br />{{cc/wind_condition}}</p> </div> </div> <div class="footer"> <ul> <li> {{fc:1/img_tag}}<br /> <strong>{{fc:1/month}}/{{fc:1/day}}</strong> <span class="high">{{fc:1/high}}</span>/<span class="low">{{fc:1/low}}</span> </li> <li> {{fc:2/img_tag}}<br /> <strong>{{fc:2/month}}/{{fc:2/day}}</strong> <span class="high">{{fc:2/high}}</span>/<span class="low">{{fc:2/low}}</span> </li> <li> {{fc:3/img_tag}}<br /> <strong>{{fc:3/month}}/{{fc:3/day}}</strong> <span class="high">{{fc:3/high}}</span>/<span class="low">{{fc:3/low}}</span> </li> </ul> </div> </div>

$googleWeatherApi_class->getArr( $p1:string , $p2:string , $hl:string )

引数からxmlを入手し配列へ再加工

引数内容型初期値サンプル
$p1 都市名 stringNULLsapporo、札幌、札幌市
$p2 地域名 stringNULLhokkaido、北海道
$hl 国コード(言語)stringNULLjp
戻り値内容
object 地域情報・今日の天気・今日から3日後までの4日間の天気予報
config_data array / Google Weather API が返すコンフィグ値
KEY内容
[version] Google Weather API 純正情報
[module_id] Google Weather API 純正情報
[tab_id] Google Weather API 純正情報
[mobile_row] Google Weather API 純正情報
[mobile_zipped]Google Weather API 純正情報
[row] Google Weather API 純正情報
[section] Google Weather API 純正情報
{{cd/version}}と指定した場所が上記値と置き換わる
例){{cd/mobile_row}} {{cd/section}}
forecast_information array / 地域情報・取得時間 / Google Weather API 純正情報および拡張情報
KEY内容サンプル備考
[city] 都市名全文Sapporo, Hokkaido PrefectureGoogle Weather API 純正情報
[postal_code] GET値 sapporo,hokkaido Google Weather API 純正情報
[latitude_e6] 緯度 Google Weather API 純正情報
[longitude_e6] 経度 Google Weather API 純正情報
[forecast_date] 今日の日付2011-09-02 Google Weather API 純正情報
[current_date_time]データ時間2011-09-02 10:30:00 +0000 Google Weather API 純正情報
[unit_system] 国コード SI Google Weather API 純正情報
[time_stamp] タイムスタンプ1314889200 独自
[year] 西暦 2011 独自
[year_ja] 和暦 23 独自
[month] 月 9 独自
[day] 日 2 独自
[postal_code1]GET値 sapporo or 札幌市 独自
[postal_code2]GET値 hokkaido or 北海道独自
{{fi/city}}と指定した場所が上記値と置き換わる
例){{fi/current_date_time}} {{fi/time_stamp}} {{fi/postal_code2}}
current_conditions array / 現在の天気情報 / Google Weather API 純正情報および拡張情報
KEY内容サンプル備考
[condition] 天候 にわか雨 Google Weather API 純正情報
[temp_f] 華氏 70 Google Weather API 純正情報
[temp_c] 摂氏 21 Google Weather API 純正情報
[humidity] 湿度 湿度 : 94% Google Weather API 純正情報
[icon] 画像パスhttp://www.google.com/ig/images/weather/jp_rainy.gifGoogle Weather API 純正情報 + α
[wind_condition] 風 風: 北 4 m/sGoogle Weather API 純正情報
[img_tag] 画像タグ<img src="[icon]" alt="[condition]" />独自
[humidity_only] 華氏 94% 独自
[wind_condition_only]華氏 北 4 m/s 独自
{{cc/condition}}と指定した場所が上記値と置き換わる
例){{cc/humidity}} {{cc/wind_condition}} {{cc/wind_condition_only}}
forecast_conditions array / 本日を含む4日間の予報 / Google Weather API 純正情報および拡張情報
array( [0]=>今日 , [1]=>明日 , [2]=>明後日 , [3]=>明々後日 )
KEY内容サンプル備考
[day_of_week] 曜日 金 Google Weather API 純正情報
[low] 最低気温 24 Google Weather API 純正情報
[high] 最高気温 26 Google Weather API 純正情報
[icon] 画像パス http://www.google.com/ig/images/weather/jp_rainy.gifGoogle Weather API 純正情報 + α
[condition] 天候 雨 Google Weather API 純正情報
[img_tag] 画像タグ <img src="[icon]" alt="[condition]" />独自
[time_stamp] タイムスタンプ1314889200独自
[forecast_date]今日の日付 2011-09-02独自
[year] 西暦 2011 独自
[year_ja] 和暦 23 独自
[month] 月 9 独自
[day] 日 2 独自
{{fc/day_of_week}}と指定した場所が上記値と置き換わる
例){{fc/year_ja}} {{fc/month}} {{fc/day}}

[ リターンオブジェクトのサンプル ]

stdClass Object ( [config_data] => Array ( [version] => 1 [module_id] => 0 [tab_id] => 0 [mobile_row] => 0 [mobile_zipped] => 1 [row] => 0 [section] => 0 ) [forecast_information] => Array ( [city] => Sapporo, Hokkaido Prefecture [postal_code] => sapporo,hokkaido [latitude_e6] => [longitude_e6] => [forecast_date] => 2011-09-06 [current_date_time] => 2011-09-06 07:30:00 +0000 [unit_system] => SI [time_stamp] => 1315234800 [year] => 2011 [year_ja] => 23 [month] => 9 [day] => 6 [postal_code1] => sapporo [postal_code2] => hokkaido ) [current_conditions] => Array ( [condition] => 雨 [temp_f] => 66 [temp_c] => 19 [humidity] => 湿度 : 94% [icon] => http://www.google.com/ig/images/weather/jp_rainy.gif [wind_condition] => 風: 南東 3 m/s [img_tag] => <img src="http://www.google.com/ig/images/weather/jp_rainy.gif" alt="雨" /> [humidity_only] => 94% [wind_condition_only] => 南東 3 m/s ) [forecast_conditions] => Array ( [0] => Array ( [day_of_week] => 火 [low] => 21 [high] => 22 [icon] => http://www.google.com/ig/images/weather/jp_rainy.gif [condition] => 雨 [img_tag] => <img src="http://www.google.com/ig/images/weather/jp_rainy.gif" alt="雨" /> [time_stamp] => 1315234800 [forecast_date] => 2011-09-06 [year] => 2011 [year_ja] => 23 [month] => 9 [day] => 6 ) [1] => Array ( [day_of_week] => 水 [low] => 16 [high] => 24 [icon] => http://www.google.com/ig/images/weather/jp_rainysometimescloudy.gif [condition] => 雨の可能性 [img_tag] => <img src="http://www.google.com/ig/images/weather/jp_rainysometimescloudy.gif" alt="雨の可能性" /> [time_stamp] => 1315321200 [forecast_date] => 2011-09-07 [year] => 2011 [year_ja] => 23 [month] => 9 [day] => 7 ) [2] => Array ( [day_of_week] => 木 [low] => 17 [high] => 27 [icon] => http://www.google.com/ig/images/weather/jp_rainysometimescloudy.gif [condition] => 雨の可能性 [img_tag] => <img src="http://www.google.com/ig/images/weather/jp_rainysometimescloudy.gif" alt="雨の可能性" /> [time_stamp] => 1315407600 [forecast_date] => 2011-09-08 [year] => 2011 [year_ja] => 23 [month] => 9 [day] => 8 ) [3] => Array ( [day_of_week] => 金 [low] => 19 [high] => 28 [icon] => http://www.google.com/ig/images/weather/jp_sunny.gif [condition] => ところにより晴れ [img_tag] => <img src="http://www.google.com/ig/images/weather/jp_sunny.gif" alt="ところにより晴れ" /> [time_stamp] => 1315494000 [forecast_date] => 2011-09-09 [year] => 2011 [year_ja] => 23 [month] => 9 [day] => 9 ) ) )

$googleWeatherApi_class->rawXml( $p1:string , $p2:string , $hl:string )

引数から Google Weather にてxmlを取得

引数内容型初期値サンプル
$p1 都市名 stringNULLsapporo、札幌、札幌市
$p2 地域名 stringNULLhokkaido、北海道
$hl 国コード(言語)stringNULLjp
戻り値内容
xmlGoogle Weather 純正データ