PHP code example of sunmking / amap-weather
1. Go to this page and download the library: Download sunmking/amap-weather library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sunmking / amap-weather example snippets
$weather = new Weather($key);
$response = $weather->getLiveWeather('深圳');
$response = $weather->getForecastsWeather('深圳');
$response = $weather->getLiveWeather('深圳', 'xml');
json
{
"status": "1",
"count": "1",
"info": "OK",
"infocode": "10000",
"forecasts": [
{
"city": "深圳市",
"adcode": "440300",
"province": "广东",
"reporttime": "2018-08-21 11:00:00",
"casts": [
{
"date": "2018-08-21",
"week": "2",
"dayweather": "雷阵雨",
"nightweather": "雷阵雨",
"daytemp": "31",
"nighttemp": "26",
"daywind": "无风向",
"nightwind": "无风向",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2018-08-22",
"week": "3",
"dayweather": "雷阵雨",
"nightweather": "雷阵雨",
"daytemp": "32",
"nighttemp": "27",
"daywind": "无风向",
"nightwind": "无风向",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2018-08-23",
"week": "4",
"dayweather": "雷阵雨",
"nightweather": "雷阵雨",
"daytemp": "32",
"nighttemp": "26",
"daywind": "无风向",
"nightwind": "无风向",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2018-08-24",
"week": "5",
"dayweather": "雷阵雨",
"nightweather": "雷阵雨",
"daytemp": "31",
"nighttemp": "26",
"daywind": "无风向",
"nightwind": "无风向",
"daypower": "≤3",
"nightpower": "≤3"
}
]
}
]
}
xml
<response>
<status>1</status>
<count>1</count>
<info>OK</info>
<infocode>10000</infocode>
<lives type="list">
<live>
<province>广东</province>
<city>深圳市</city>
<adcode>440300</adcode>
<weather>中雨</weather>
<temperature>27</temperature>
<winddirection>西南</winddirection>
<windpower>5</windpower>
<humidity>94</humidity>
<reporttime>2018-08-21 16:00:00</reporttime>
</live>
</lives>
</response>