インターネットはリアルと対極にあると考えがちですが、実際にはリアルを補完する存在として使われることのが多いです。スマートフォンでは天気アプリが使われることが多く、Yahooの雨雲レーダーのように5分後、10分後の天気が気になるケースはよくあります。
そんな訳で天気情報は以外とオンラインでもウケが良いです。もしWebサイトに載せるながらReally Simple Weatherを使ってみましょう。
Really Simple Weatherの使い方
Really Simple Weatherはとてもシンプルに書けます。依存ライブラリはありません。
<div id="weather"></div>
<script>
reallySimpleWeather.weather({
wunderkey: '', // leave blank for Yahoo
location: 'Bend, OR', //your location
woeid: '', // "Where on Earth ID"
unit: 'f', // 'c' also works
success: function(weather) {
html = '<h2>'+weather.temp+'°'+weather.units.temp+'</h2>';
html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
html += '<li>'+weather.currently+'</li>';
html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';
document.getElementById('weather').innerHTML = html;
},
error: function(error) {
document.getElementById('weather').innerHTML = '<p>'+error+'</p>';
}
});</script>
reallySimpleWeather.weatherを実行するとsuccessに対して天気情報が返ってきます。華氏、摂氏のどちらでも取得できます。
特定の都市を指定することも、位置情報を使って一番近い天気情報を取得することもできます。旅行先の天気情報をチェックしたりすることはよくあるので、旅先情報やグルメ情報を提供するサイトとの相性は良いでしょう。
Really Simple WeatherはJavaScript製のオープンソース・ソフトウェア(MIT License/GPL)です。
Really Simple Weather - Pure JavaScript Weather Plugin
a12k/reallySimpleWeather: simple javascript weather plugin with no dependencies
MOONGIFTの関連記事