緯度経度から天気予報を表示させるために、Google Weather APIを使いました。下記はその東京スカイツリー周辺の天気予報です

1) http://withmama.lolipop.jp/kaihatsu/weather/hatena.php (ソースをご高覧ください)
ところが、東京スカイツリーの天気予報をGoogleで表示すると
2) http://bit.ly/IOqegi です
1)と2)の内容があまりに違うので驚いています。
そこで質問です。
a)そもそもGoogle Weather APIはあまり信頼がおけないものなのでしょうか?
b)信頼がおけるが、私の処理方法が間違っているのでこのような違いが発生したのでしょうか?
 処理方法とは、主に上記1)のページでの以下の2つです。
 ☆$now_yobi = Date("D", strtotime("now")+32400); などの日本時間への変更
 ☆//華氏摂氏変換
function convertF2C($val) {
return round(($val-32)*5/9);
}
どうぞ、よろしくご教示ください。

回答の条件
  • 1人5回まで
  • 登録:
  • 終了:2012/04/14 16:32:58
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

ベストアンサー

id:taknt No.1

回答回数13539ベストアンサー獲得回数1198

ポイント100pt

/13
14邃�
27邃�
4/14
16邃�
30邃�
4/15
18邃�
31邃�


この下の 31って何でしょうか?
もしかして 最高気温?
これじゃ夏日ですよねぇ。

どこか 算出の仕方が 間違ってるんじゃないでしょうか?


http://billboardtop100.net/2011/04/google-weather-api-php.html
こちらに使い方が載ってますね。

あと 墨田区は
http://www.google.com/ig/api?weather=,,,35423800,139480600
で取得できます。

これをみると 温度の変換は いらない感じですね。
天気も土曜は 雨になっているようですし。

その他の回答1件)

id:taknt No.1

回答回数13539ベストアンサー獲得回数1198ここでベストアンサー

ポイント100pt

/13
14邃�
27邃�
4/14
16邃�
30邃�
4/15
18邃�
31邃�


この下の 31って何でしょうか?
もしかして 最高気温?
これじゃ夏日ですよねぇ。

どこか 算出の仕方が 間違ってるんじゃないでしょうか?


http://billboardtop100.net/2011/04/google-weather-api-php.html
こちらに使い方が載ってますね。

あと 墨田区は
http://www.google.com/ig/api?weather=,,,35423800,139480600
で取得できます。

これをみると 温度の変換は いらない感じですね。
天気も土曜は 雨になっているようですし。

id:taknt No.2

回答回数13539ベストアンサー獲得回数1198

ポイント100pt

$lat = 35.710081;
$lng = 139.808242;

$lat = round($lat);
$lng = round($lng);

これだと 全然違うところを呼びだしてしまいますね。

緯度経度だと
http://www.google.com/ig/api?weather=,,,35423800,139480600
というように呼ばないとだめです。


なので上記の箇所を
$lat = ',,,35710081';
$lng = ',139808242';

//$lat = round($lat);
//$lng = round($lng);
と変えてみました。

id:ozaki

コメント、ありがとうございました。apiの呼び出し方法が間違えていたのですね($latと$lng)。おかげ様で目的を達することができました。
感謝!

2012/04/14 16:34:01
  • id:taknt
    >http://withmama.lolipop.jp/kaihatsu/weather/hatena.php (ソースをご高覧ください)

    ソースを見ても 変換された結果しか出ないので コメントに phpのソースを 貼りつけてもらっていいですか?
  • id:ozaki
    返信、遅くなりました。ソースは以下です。どうぞ、よろしくお願いいたします。

    <?
    //経度・緯度から天気情報を入手
    //経度・緯度は整数でないと使えないみたい



    $lat = 35.710081;
    $lng = 139.808242;

    $lat = round($lat);
    $lng = round($lng);
    $weather_req = 'http://www.google.com/ig/api?weather=';
    $weather_req .= $lat;
    $weather_req .= $lng;
    //$weather_req .= '&hl=ja';
    $str = file_get_contents($weather_req);
    //SJISだと解析出来なかったのでUTF-8に変換してる
    //$str = mb_convert_encoding($str, 'UTF-8', 'Shift-JIS');
    $weather_xml = simplexml_load_string ($str);
    /*
    echo "<pre>";
    print_r($weather_xml);
    echo "</pre>";
    */

    $now_md = Date("n/d", strtotime("now")+32400);
    $now_yobi = Date("D", strtotime("now")+32400);

    $tommorow_md = Date("n/d", strtotime("now")+118800);
    $tommorow_yobi = Date("D", strtotime("now")+118800);

    $nexttommorow_md = Date("n/d", strtotime("now")+205200);
    $nexttommorow_yobi = Date("D", strtotime("now")+205200);

    $nextnexttommorow_md = Date("n/d", strtotime("now")+291600);
    $nextnexttommorow_yobi = Date("D", strtotime("now")+291600);

    //華氏摂氏変換
    function convertF2C($val) {
    return round(($val-32)*5/9);
    }
    ?>
    <table>


    <?
    foreach ($weather_xml->weather->forecast_conditions as $forecast) {
    $yobi = $forecast->day_of_week[data] ;
    if ($yobi==$now_yobi){
    ?>
    <tr>
    <td colspan="2"><? echo $now_md; ?></td>
    </tr>
    <tr>
    <td><img src="http://www.google.com<?=$forecast->icon['data']?>"></td>
    <td>
    <?

    $low = $forecast->low['data'];
    echo convertF2C($low).'℃';
    ?>
    <br>
    <?
    $high = $forecast->high['data'];
    echo convertF2C($high).'℃';
    ?>
    </td>
    </tr>
    <?
    }
    else if ($yobi==$tommorow_yobi){
    ?>
    <tr>
    <td colspan="2"><? echo $tommorow_md; ?></td>
    </tr>
    <tr>
    <td><img src="http://www.google.com<?=$forecast->icon['data']?>"></td>
    <td>
    <?
    $low = $forecast->low['data'];
    echo convertF2C($low).'℃';
    ?>
    <br>
    <?
    $high = $forecast->high['data'];
    echo convertF2C($high).'℃';
    ?>
    </td>
    </tr>
    <?
    }
    else if ($yobi==$nexttommorow_yobi){
    ?>
    <tr>
    <td colspan="2"><? echo $nexttommorow_md; ?></td>
    </tr>
    <tr>
    <td><img src="http://www.google.com<?=$forecast->icon['data']?>"></td>
    <td>
    <?
    $low = $forecast->low['data'];
    echo convertF2C($low).'℃';
    ?>
    <br>
    <?
    $high = $forecast->high['data'];
    echo convertF2C($high).'℃';
    ?>
    </td>
    </tr>
    <?
    }
    else if ($yobi==$nextnexttommorow_yobi){
    ?>
    <tr>
    <td colspan="2"><? echo $nextnexttommorow_md; ?></td>
    </tr>
    <tr>
    <td><img src="http://www.google.com<?=$forecast->icon['data']?>"></td>
    <td>
    <?
    $low = $forecast->low['data'];
    echo convertF2C($low).'℃';
    ?>
    <br>
    <?
    $high = $forecast->high['data'];
    echo convertF2C($high).'℃';
    ?>
    </td>
    </tr>
    <?
    }

    }
    ?>

    </table>

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません