百度天气预报接口

简介: 百度提供天气预报查询接口API,可以根据经纬度/城市名查询天气情况,我们可以在微信公众平台开发中调用这一接口。 接口说明 根据经纬度/城市名查询天气的结果 接口示例 http://api.

百度提供天气预报查询接口API,可以根据经纬度/城市名查询天气情况,我们可以在微信公众平台开发中调用这一接口。

接口说明

根据经纬度/城市名查询天气的结果

接口示例

http://api.map.baidu.com/telematics/v3/weather?location=北京&output=json&ak=yourkey
百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key

接口参数说明

参数类型 参数名称 是否必须 具体描述
String ak true 开发者密钥
String sn false 若用户所用ak的校验方式为sn校验时该参数必须。 
String location true 输入城市名或经纬度,城市名称如:北京,经纬度格式为lng,lat坐标如: location=116.305145,39.982368;城市天气预报中间"|"分隔,location=116.305145,39.982368| 122.305145,36.982368|….
String output false 输出的数据格式,默认为xml格式,当output设置为’json’时,输出的为json格式的数据;
String coord_type false 请求参数坐标类型,默认为gcj02经纬度坐标。允许的值为bd09ll、bd09mc、gcj02、wgs84。bd09ll表示百度经纬度坐标,bd09mc表示百度墨卡托坐标,gcj02表示经过国测局加密的坐标。wgs84表示gps获取的坐标。

 

返回结果

参数名称 含义 说明
currentCity 当前城市 返回城市名
status 返回结果状态信息  
date 当前时间 年-月-日
results 天气预报信息 白天可返回近期3天的天气情况(今天、明天、后天)、晚上可返回近期4天的天气情况(今天、明天、后天、大后天)
results.currentCity 当前城市  
results.weather_data weather_data.date 天气预报时间  
weather_data.dayPictureUrl 白天的天气预报图片url  
weather_data.nightPictureUrl 晚上的天气预报图片url  
weather_data.weather 天气状况 所有天气情况(”|”分隔符):晴|多云|阴|阵雨|雷阵雨|雷阵雨伴有冰雹|雨夹雪|小雨|中雨|大雨|暴雨|大暴雨|特大暴雨|阵雪|小雪|中雪|大雪|暴雪|雾|冻雨|沙尘暴|小雨转中雨|中雨转大雨|大雨转暴雨|暴雨转大暴雨|大暴雨转特大暴雨|小雪转中雪|中雪转大雪|大雪转暴雪|浮尘|扬沙|强沙尘暴|霾
weather_data.wind 风力  
weather_data.temperature 温度  

返回xml格式的数据

<?xml version="1.0" encoding="utf-8" ?> 
<CityWeatherResponse>
    <status>success</status>
    <date>2014-05-03</date>
    <results> 
     
        <currentCity>北京</currentCity>
        <weather_data>
                            <date>周六(今天, 实时:22℃)</date>
                <dayPictureUrl>http://api.map.baidu.com/images/weather/day/leizhenyu.png</dayPictureUrl>
                <nightPictureUrl>http://api.map.baidu.com/images/weather/night/duoyun.png</nightPictureUrl>
                <weather>雷阵雨转多云</weather>
                <wind>北风5-6级</wind>
                <temperature>24 ~ 11℃</temperature>
                            <date>周日</date>
                <dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl>
                <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
                <weather>多云转晴</weather>
                <wind>北风4-5级</wind>
                <temperature>19 ~ 8℃</temperature>
                            <date>周一</date>
                <dayPictureUrl>http://api.map.baidu.com/images/weather/day/qing.png</dayPictureUrl>
                <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
                <weather>晴</weather>
                <wind>微风</wind>
                <temperature>21 ~ 9℃</temperature>
                            <date>周二</date>
                <dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl>
                <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
                <weather>多云转晴</weather>
                <wind>微风</wind>
                <temperature>21 ~ 10℃</temperature>
                    </weather_data>
        </results>
</CityWeatherResponse>

返回json格式的数据

{
    "error": 0,
    "status": "success",
    "date": "2014-05-03",
    "results": [
        {
            "currentCity": "北京",
            "weather_data": [
                {
                    "date": "周六(今天, 实时:22℃)",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    "weather": "雷阵雨转多云",
                    "wind": "北风5-6级",
                    "temperature": "24 ~ 11℃"
                },
                {
                    "date": "周日",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
                    "weather": "多云转晴",
                    "wind": "北风4-5级",
                    "temperature": "19 ~ 8℃"
                },
                {
                    "date": "周一",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
                    "weather": "晴",
                    "wind": "微风",
                    "temperature": "21 ~ 9℃"
                },
                {
                    "date": "周二",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
                    "weather": "多云转晴",
                    "wind": "微风",
                    "temperature": "21 ~ 10℃"
                }
            ]
        }
    ]
}
 
  

 

效果如下:

 

 

购买天气预报功能源码

 
  

微信扫描二维码关注后返回购买图文链接,然后进入购买:



目录
相关文章
|
关系型数据库 MySQL 数据库
django4版本提示 django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.7.26)
在学习Django时,用户遇到`django.db.utils.NotSupportedError`,提示需要MySQL 8.0.25或更高版本,但其系统上是5.7.26。为解决这个问题,用户决定不升级MySQL,而是选择注释掉Django源码中的数据库版本检查。通过Python命令行找到Django安装路径,进入`db/backends/base/base.py`,注释掉`self.check_database_version_supported()`函数
2254 0
|
Web App开发 安全 网络协议
Qt开发技术:QWebSocket客户端、服务端介绍与开发
Qt开发技术:QWebSocket客户端、服务端介绍与开发
Qt开发技术:QWebSocket客户端、服务端介绍与开发
|
11月前
|
负载均衡 监控 Java
Spring Cloud 为什么是微服务时代中伟大的产物
Spring Boot 提升开发效率,但单体架构难以应对复杂业务。微服务通过拆分系统解决演进难题,而 Spring Cloud 以“抽象+插拔”模式整合服务发现、负载均衡、熔断等能力,推动微服务落地。OpenFeign 作为核心调用组件,串联治理链路,实现低侵入、高可用的分布式调用。
339 10
|
9月前
|
自然语言处理 安全 搜索推荐
ChatGPT的实用应用场景汇总
随着人工智能技术的普及,ChatGPT已从单纯的聊天工具,转变为覆盖工作、学习、生活、娱乐等多领域的实用助手。
818 0
|
jenkins 持续交付 开发工具
jenkins学习笔记之一:流水线基础语法
jenkins学习笔记之一:流水线基础语法
1113 1
计算机网络实验(华为eNSP模拟器)——第十章 Eth-Trunk(链路聚合)
计算机网络实验(华为eNSP模拟器)——第十章 Eth-Trunk(链路聚合)
计算机网络实验(华为eNSP模拟器)——第十章 Eth-Trunk(链路聚合)
|
小程序 JavaScript 开发者
微信小程序分包的相关概念和使用
本文介绍了微信小程序分包的概念、优势、配置方法、加载规则、体积限制,以及独立分包和分包预下载的配置,旨在帮助开发者优化小程序的加载速度和开发效率。
|
机器学习/深度学习 算法
【机器学习】揭秘GBDT:梯度提升决策树
【机器学习】揭秘GBDT:梯度提升决策树
1258 0
|
安全 Linux Android开发
SELinux策略语法以及示例策略
本文来讲述 SELinux 策略常用的语法,然后解读一下 SELinux 这个项目中给出的示例策略
527 2