OpenWeatherMap API指南
1、注册申请“API密钥”:https://home.openweathermap.org/users/sign_up
四种调用方式:
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调用的示例:
多语言支持:
您可以使用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