php百度天气api接口,php使用百度天气接口示例

news/2024/7/4 9:08:34

这篇文章主要介绍了百度天气接口使用示例,需要的朋友可以参考下

注意地区要转码的

百度ak申请地址:

复制代码 代码如下:

$city="嘉兴";

$content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");

print_r(json_decode($content));

复制代码 代码如下:

{

error: 0,

status: "success",

date: "2014-04-18",

results: [

{

currentCity: "嘉兴",

weather_data: [

{

date: "今天(周三)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "微风",

temperature: "23℃"

},

{

date: "明天(周四)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",

weather: "雷阵雨转中雨",

wind: "微风",

temperature: "29~22℃"

},

{

date: "后天(周五)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "阴转多云",

wind: "微风",

temperature: "31~23℃"

},

{

date: "大后天(周六)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "微风",

temperature: "31~24℃"

}

]

},

{

currentCity: "合肥市",

weather_data: [

{

date: "今天(周三)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "东风3-4级",

temperature: "27℃"

},

{

date: "明天(周四)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "东北风3-4级",

temperature: "35~27℃"

},

{

date: "后天(周五)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "南风",

temperature: "35~27℃"

},

{

date: "大后天(周六)",

dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",

nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",

weather: "多云",

wind: "东风",

temperature: "34~27℃"

}

]

}

]

}


http://www.niftyadmin.cn/n/3297554.html

相关文章

redis -Spring与Jedis集群 Sentinel

首先不得不服Spring这个宇宙无敌的开源框架,几乎整合了所有流行的其它框架,http://projects.spring.io/spring-data/ 从这上面看,当下流行的redis、solr、hadoop、mongoDB、couchBase... 全都收入囊中。对于redis整合而言,主要用到…

轮播图会用到java的哪些功能,原生JS实现的轮播图功能详解

本文实例讲述了原生JS实现的轮播图功能。分享给大家供大家参考,具体如下:一、效果预览:由于只能上传2M以下的图片,这里只截取了自动切换的效果:二、编写语言HTML、CSS、原生JS三、编写思路(一)HTML部分1、.slide意为滑…

常用 ajax 框架比较--摘自网络

No1—Prototype http://www.prototypejs.org/特点:一个非常优雅的JS库,定义了JS的面向对象扩展,DOM操作API,事件等等,之上还有rico/script.aculo.us实现一些JS组件功能和效果(尚不够完善),以prototype为核心…

kafka mysql 迁移,kafka迁移数据目录

问题先前存储kafka日志的磁盘空间太小,zabbix警报不断,于是加了磁盘,将日志存到新磁盘上。解决方案依次在每台机器上操作,保证有机器能响应producer和consumer的操作。加磁盘需要重启服务器。1. 拷贝日志服务器启动后,…

js时间格式化通用方法

/*** 时间工具类*//*** 获取现在的时间戳(精确到s)* 使用:new Date().nowTimestamp* type {number}*/ Date.prototype.nowTimestamp Date.parse(new Date()) / 1000;/*** 时间戳转换成Date* 使用:new Date().timestampToDate(149…

redis 3.0的集群部署

文章转载自:http://hot66hot.iteye.com/blog/2050676 转载请注明出处:http://hot66hot.iteye.com/admin/blogs/2050676 最近研究redis-cluster,正好搭建了一个环境,遇到了很多坑,系统的总结下,等到redis3 release出来后,换掉memCache 集群. 一:关于redis…

部分去重复php,找到重复小数的重复部分 – PHP

要说这并不像我想象的那么容易.但我得到了它的工作.我确信有一种更有效的方法可以做到这一点,希望其他人会改进这一点.特别是它被打印的部分.$number1 $number / $divisor;if(findRepeat( $number1 ) ! false){$result findRepeat($number1);$leadingNum strstr($number1, .…

深入理解ASP.NET MVC(4)

系列目录 DataTokens和Areas机制 到目前为止Route对象只剩下DataTokens属性没有涉及,事实上这个Areas机制的核心。 DataTokens实际上也是一个RouteValueDictionary,在用MapRoute方法构造在Route构造的时候,可以传一个namespaces字符串数组&am…