359
358

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

天気情報を取得する

Last updated at Posted at 2013-12-16

天気情報を取得できるAPIはたくさんありますが、
今回は、OpenWeatherMap - actual and forecast weatherという無料サービスを使って、天気情報をjsonで取得します。

##都市名で取得する

http://api.openweathermap.org/data/2.5/weather?q="都市名","国"

//例
http://api.openweathermap.org/data/2.5/weather?q=Tokyo,jp

##緯度、経度で取得する

http://api.openweathermap.org/data/2.5/weather?lat="緯度"&lon="経度"

//例
http://api.openweathermap.org/data/2.5/weather?lat=35&lon=140

###取得結果

{
    "base": "cmc stations", 
    "clouds": {
        "all": 36
    }, 
    "cod": 200, 
    "coord": {
        "lat": 35.64, 
        "lon": 139.68
    }, 
    "dt": 1387204059, 
    "id": 1864381, 
    "main": {
        "humidity": 18, 
        "pressure": 1019, 
        "temp": 279.63, 
        "temp_max": 282.04, 
        "temp_min": 277.59
    }, 
    "name": "Denenchōfu", 
    "sys": {
        "country": "JP", 
        "message": 0.0086, 
        "sunrise": 1387143858, 
        "sunset": 1387178986
    }, 
    "weather": [
        {
            "description": "scattered clouds", 
            "icon": "03n", 
            "id": 802, 
            "main": "Clouds"
        }
    ], 
    "wind": {
        "deg": 306, 
        "gust": 4.63, 
        "speed": 4.11
    }
}

##取得できる値

パラメータ 説明
temp 気温
temp_min 最低気温
temp_max 最高気温
icon 天気アイコン
main 天気
lat 緯度
lon 経度
pressure 気圧
sea_level 海面
humidity 湿度
speed 風速
name 都市名
country 国名
sunrise 日の出時間
sunset 日没時間

##天気アイコン取得方法

http://openweathermap.org/img/w/"iconの値".png

説明:API/Weather Condition Codes - OpenWeatherMap

##その他
・天気の更新は10分単位
・対応は世界7万都市
・利用料無料

359
358
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
359
358

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?