1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2018 - present |
4
|
|
|
* Google Maps PHP - Elevation.php |
5
|
|
|
* author: Roberto Belotti - [email protected] |
6
|
|
|
* web : robertobelotti.com, github.com/biscolab |
7
|
|
|
* Initial version created on: 28/9/2018 |
8
|
|
|
* MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Biscolab\GoogleMaps\Api; |
12
|
|
|
|
13
|
|
|
use Biscolab\GoogleMaps\Abstracts\Api; |
14
|
|
|
use Biscolab\GoogleMaps\Fields\GoogleMapsRequestFields; |
15
|
|
|
use Biscolab\GoogleMaps\Http\GoogleMapsResultsCollection; |
16
|
|
|
use Biscolab\GoogleMaps\Http\Result\ElevationResultsCollection; |
17
|
|
|
use Biscolab\GoogleMaps\Object\LatLng; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Elevation |
21
|
|
|
* @package Biscolab\GoogleMaps\Api |
22
|
|
|
* |
23
|
|
|
* @since 0.3.0 |
24
|
|
|
* @see https://developers.google.com/maps/documentation/elevation/start |
25
|
|
|
*/ |
26
|
|
|
class Elevation extends Api { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_ENDPOINT = 'elevation'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $result_collection = ElevationResultsCollection::class; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Positional Requests |
40
|
|
|
* |
41
|
|
|
* @param LatLng|string|array $locations |
42
|
|
|
* This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline |
43
|
|
|
* |
44
|
|
|
* @since 0.3.0 |
45
|
|
|
* |
46
|
|
|
* @return GoogleMapsResultsCollection |
47
|
|
|
*/ |
48
|
|
|
public function getByLocations($locations): GoogleMapsResultsCollection { |
49
|
|
|
|
50
|
|
|
$locations = $this->parseLocations($locations); |
51
|
|
|
|
52
|
|
|
$request = $this->createRequest([ |
53
|
|
|
GoogleMapsRequestFields::LOCATIONS => $locations |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
return $this->getResultsCollections($request); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $locations |
61
|
|
|
* |
62
|
|
|
* @since 0.3.0 |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function parseLocations($locations): string { |
67
|
|
|
|
68
|
|
|
if (is_array($locations)) { |
69
|
|
|
$locations = implode('|', array_map(function ($item) { |
70
|
|
|
|
71
|
|
|
return (string)$item; |
72
|
|
|
}, $locations)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return (string)$locations; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |