PHP code example of walker-distance / weather
1. Go to this page and download the library: Download walker-distance/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/ */
walker-distance / weather example snippets
php artisan vendor:publish --provider='WalkerDistance\Weather\ServiceProvider'
WEATHER_API_KEY=*******************
$city = '北京';
$type = 'all'; //可以不填 默认为实时天气 all表示天气预报
$format = 'json'; //默认为json 支持xml(json)
app('weather')->getweather($city, $type = null, $format = null);
//在laravel中使用
protected $weather;
public function __construct(Weather $weather)
{
$this->weather = $weather;
}
//在方法中使用
public function getWeather(Request $request)
{
//$city = '北京';
//$type = 'all'; //可以不填 默认为实时天气 all表示天气预报
//$format = 'json'; //默认为json 支持xml(json)
$city = $request->get('city');
$response = $this->weather->getWeather($city ?: '北京');
return $this->success($response);
}
//$city = '北京';
//$type = 'all'; //可以不填 默认为实时天气 all表示天气预报
//$format = 'json'; //默认为json 支持xml(json)
$city = '天津';
$key = '';
$weather = new Weather($key);
$response = $weather->getWeather($city,$type = null,$format = null);