注意地區要轉碼的
百度ak申請地址:http://lbsyun.baidu.com/apiconsole/key
復制代碼 代碼如下:
<?php
$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℃"
}
]
}
]
}