|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rawaby88\OpenWeatherMap\Services; |
|
4
|
|
|
|
|
5
|
|
|
use http\Exception\InvalidArgumentException; |
|
6
|
|
|
use Rawaby88\OpenWeatherMap\Interfaces\CWMultiResultInterface; |
|
7
|
|
|
use Rawaby88\OpenWeatherMap\Traits\CWMultiResultTrait; |
|
8
|
|
|
use Rawaby88\OpenWeatherMap\WeatherFactory; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class CWByCitiesInCircle. |
|
12
|
|
|
*/ |
|
13
|
|
|
class CWByCitiesInCircle extends WeatherFactory implements CWMultiResultInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use CWMultiResultTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var float Geographical coordinates (latitude). |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $lat; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var float Geographical coordinates (longitude). |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $lon; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var int Number of cities around the point that should be returned. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $cityCount; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* CWByCitiesInCircle constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* returns the data from cities within the defined rectangle specified by the geographic coordinates. |
|
34
|
|
|
* There is a limit of 25 square degrees for Free and Startup plans. |
|
35
|
|
|
* |
|
36
|
|
|
* @param float $lat Geographical coordinates (latitude). |
|
37
|
|
|
* @param float $lon Geographical coordinates (longitude). |
|
38
|
|
|
* @param int $cityCount Number of cities around the point that should be returned. The default number of cities is 5, the maximum is 50. |
|
39
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(float $lat, float $lon, int $cityCount = 5) |
|
42
|
|
|
{ |
|
43
|
|
|
if ($cityCount > 50) { |
|
44
|
|
|
throw new InvalidArgumentException('The maximum number of cities 50.'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
parent::__construct(); |
|
48
|
|
|
$this->apiCall = 'find'; |
|
49
|
|
|
$this->lat = $lat; |
|
50
|
|
|
$this->lon = $lon; |
|
51
|
|
|
$this->cityCount = $cityCount; |
|
52
|
|
|
$this->params = $this->paramsToArray(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Generate query parameters for api call. |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
private function paramsToArray(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
'lat' => $this->lat, |
|
63
|
|
|
'lon' => $this->lon, |
|
64
|
|
|
'cnt' => $this->cityCount, |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|