Help us understand the problem. What is going on with this article?

天気情報を取得する

More than 5 years have passed since last update.

天気情報を取得できる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万都市
・利用料無料

s0hno
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした