OpenWeatherMap API指南

OpenWeatherMap API指南

1、註冊申請“API密鑰”:https://home.openweathermap.org/users/sign_up

示例API密鑰:https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22

四種調用方式:

1、按城市名稱

參數:

q城市名稱和國家/地區代碼除以逗號,使用ISO 3166國家/地區代碼

API調用的示例:

api.openweathermap.org/data/2.5/weather?q=London

api.openweathermap.org/data/2.5/weather?q=London,uk

2、按城市ID

API調用的示例:

api.openweathermap.org/data/2.5/weather?id=2172797

3、按地理座標

API調用:

api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}

4、按郵政編碼

API調用的示例:

api.openweathermap.org/data/2.5/weather?zip=94040,us

多語言支持:

您可以使用lang參數以您的語言獲取輸出。我們支持以下語言,您可以使用相應的語言值: 
阿拉伯語 - ar,保加利亞語 - bg,加泰羅尼亞語 - ca,捷克語 - cz,德語 - de,希臘語 - el,英語 - en,波斯語(波斯語) - fa,芬蘭語 - fi,法語 - fr,加利西亞語 - gl,克羅地亞語 - hr,匈牙利語 - hu,意大利語 - 日語 - 日語 - ja,韓語 - kr,拉脫維亞語 - la,立陶宛語 - LT,馬其頓語 - mk,荷蘭語 - nl,波蘭語 - pl,Portuguese - pt,Romanian - ro,Russian - ru,Swedish - se,Slovak - sk,Slovenian - sl,Spanish - es,Turkish - tr,Ukrainian - ua,Vietnamese - vi,簡體中文 - zh_cn,繁體中文 - ZH_TW。

API調用的示例:

http://api.openweathermap.org/data/2.5/forecast/daily?id=524901&lang=zh_cn

格式:

API調用的示例:

JSON api.openweathermap.org/data/2.5/weather?q=London

XML api.openweathermap.org/data/2.5/weather?q=London&mode=xml

HTML api.openweathermap.org/data/2.5/weather?q=London&mode=html

回調JavaScript代碼的功能

要使用JavaScript代碼,您可以將回調函數名稱傳遞給JSONP回調。 

API調用的示例:

api.openweathermap.org/data/2.5/weather?q=London,uk&callback=test

圖標地址:

URL示例: http://openweathermap.org/img/w/01d.png

或者:https://openweathermap.org/themes/openweathermap/assets/vendor/owm/img/01d.png(推薦使用)

圖標集合圖:

參數說明圖:

查看詳情訪問官網:https://openweathermap.org/api

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章