PHP code example of iidestiny / weather

1. Go to this page and download the library: Download iidestiny/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/ */

    

iidestiny / weather example snippets


use IiDestiny\Weather\Weather;

$ak = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($ak);

// 返回数组格式
$response = $weather->getWeather('深圳');

// 批量获取
$response = $weather->getWeather('深圳|北京');

// 返回 XML 格式
$response = $weather->getWeather('深圳', 'xml');

// 按坐标获取
$response = $weather->getWeather('116.30,39.98', 'json');

// 批量坐标获取
$response = $weather->getWeather('116.43,40.75|120.22,43,33', 'json');

// 自定义坐标格式(coord_type)
$response = $weather->getWeather('116.306411,39.981839', 'json', 'bd09ll');

array | string   getWeather(string $location, string $format = 'json', string $coordType = null)

function index(\IiDestiny\Weather\Weather $weather)
{
    return $weather->getWeather('北京');
}