1 | <?php |
||
2 | |||
3 | namespace kalanis\google_maps\Services; |
||
4 | |||
5 | |||
6 | use kalanis\google_maps\ServiceException; |
||
7 | use Psr\Http\Message\RequestInterface; |
||
8 | |||
9 | |||
10 | /** |
||
11 | * Timezone Service |
||
12 | * |
||
13 | * @see https://developers.google.com/maps/documentation/timezone/ |
||
14 | */ |
||
15 | class Timezone extends AbstractService |
||
16 | { |
||
17 | /** |
||
18 | * Timezone |
||
19 | * |
||
20 | * @param string|array<string> $location |
||
21 | * @param int|null $timestamp |
||
22 | * @param array<string, string|int|float> $params Query parameters |
||
23 | * @throws ServiceException |
||
24 | * @return RequestInterface |
||
25 | */ |
||
26 | 4 | public function timezone(string|array $location, ?int $timestamp = null, array $params = []): RequestInterface |
|
27 | { |
||
28 | // `location` seems to only allow `lat,lng` pattern |
||
29 | 4 | if (is_string($location)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
30 | |||
31 | 1 | $params['location'] = $location; |
|
32 | |||
33 | } else { |
||
34 | |||
35 | 3 | if (isset($location['lat']) && isset($location['lng'])) { |
|
36 | |||
37 | 1 | $params['location'] = sprintf('%1.08F,%1.08F', $location['lat'], $location['lng']); |
|
38 | |||
39 | 2 | } elseif (isset($location[0]) && isset($location[1])) { |
|
40 | |||
41 | 1 | $params['location'] = sprintf('%1.08F,%1.08F', $location[0], $location[1]); |
|
42 | |||
43 | } else { |
||
44 | |||
45 | 1 | throw new ServiceException('Passed invalid values into coordinates! You must use either array with lat and lng or 0 and 1 keys.'); |
|
46 | |||
47 | } |
||
48 | } |
||
49 | |||
50 | // Timestamp |
||
51 | 3 | $params['timestamp'] = ($timestamp) ?: time(); |
|
52 | |||
53 | 3 | return $this->getWithDefaults( |
|
54 | 3 | static::API_HOST . '/maps/api/timezone/json', |
|
55 | 3 | $this->queryParamsLang($params) |
|
56 | 3 | ); |
|
57 | } |
||
58 | } |
||
59 |