|
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
|
|
|
* Directions Service |
|
12
|
|
|
* |
|
13
|
|
|
* @see https://developers.google.com/maps/documentation/elevation/ |
|
14
|
|
|
* @see https://developers.google.com/maps/documentation/elevation/requests-elevation |
|
15
|
|
|
*/ |
|
16
|
|
|
class Elevation extends AbstractService |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Elevation |
|
20
|
|
|
* |
|
21
|
|
|
* @param string|array<string|int, float> $locations |
|
22
|
|
|
* @param array<string, string|int|float> $params Query parameters |
|
23
|
|
|
* @throws ServiceException |
|
24
|
|
|
* @return RequestInterface |
|
25
|
|
|
*/ |
|
26
|
4 |
|
public function elevation(string|array $locations, array $params = []): RequestInterface |
|
27
|
|
|
{ |
|
28
|
|
|
// `locations` seems to only allow `lat,lng` pattern |
|
29
|
4 |
|
if (is_string($locations)) { |
|
|
|
|
|
|
30
|
1 |
|
$params['locations'] = $locations; |
|
31
|
|
|
|
|
32
|
3 |
|
} elseif (isset($locations['lat']) && isset($locations['lng'])) { |
|
33
|
1 |
|
$params['locations'] = sprintf('%1.08F,%1.08F', $locations['lat'], $locations['lng']); |
|
34
|
|
|
|
|
35
|
2 |
|
} elseif (isset($locations[0]) && isset($locations[1])) { |
|
36
|
1 |
|
$params['locations'] = sprintf('%1.08F,%1.08F', $locations[0], $locations[1]); |
|
37
|
|
|
|
|
38
|
|
|
} else { |
|
39
|
1 |
|
throw new ServiceException('Passed invalid values into coordinates! You must use either preformatted string or array with lat and lng or 0 and 1 keys.'); |
|
40
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
3 |
|
return $this->getWithDefaults( |
|
44
|
3 |
|
static::API_HOST . '/maps/api/elevation/json', |
|
45
|
3 |
|
$this->queryParamsLang($params) |
|
46
|
3 |
|
); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|