1 | <?php namespace Arcanedev\GeoLocation\Google\DistanceMatrix; |
||
16 | class DistanceMatrixService extends AbstractService |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Constants |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | const BASE_URL = 'https://maps.googleapis.com/maps/api/distancematrix/json'; |
||
24 | |||
25 | /* ----------------------------------------------------------------- |
||
26 | | Properties |
||
27 | | ----------------------------------------------------------------- |
||
28 | */ |
||
29 | |||
30 | /** @var string */ |
||
31 | protected $language = 'en'; |
||
32 | |||
33 | /** @var string */ |
||
34 | protected $mode = 'driving'; |
||
35 | |||
36 | /** @var string */ |
||
37 | protected $units = 'metric'; |
||
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Getters & Setters |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Set the language. |
||
46 | * |
||
47 | * @param string $language |
||
48 | * |
||
49 | * @return self |
||
50 | */ |
||
51 | 3 | public function setLanguage($language) |
|
57 | |||
58 | /** |
||
59 | * Set the mode of transport. |
||
60 | * |
||
61 | * @param string $mode |
||
62 | * |
||
63 | * @return self |
||
64 | */ |
||
65 | 6 | public function setMode($mode) |
|
71 | |||
72 | /** |
||
73 | * Set the unit system. |
||
74 | * |
||
75 | * @param string $units |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | 6 | public function setUnits($units) |
|
85 | |||
86 | /* ----------------------------------------------------------------- |
||
87 | | Main Methods |
||
88 | | ----------------------------------------------------------------- |
||
89 | */ |
||
90 | |||
91 | /** |
||
92 | * Calculate the distance. |
||
93 | * |
||
94 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $start |
||
95 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $end |
||
96 | * @param array $options |
||
97 | * |
||
98 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
99 | */ |
||
100 | 12 | public function calculate(Position $start, Position $end, array $options = []) |
|
109 | |||
110 | /* ----------------------------------------------------------------- |
||
111 | | Other Methods |
||
112 | | ----------------------------------------------------------------- |
||
113 | */ |
||
114 | |||
115 | /** |
||
116 | * Get the default query params. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 12 | protected function getDefaultQueryParams() |
|
128 | |||
129 | /** |
||
130 | * Prepare the response. |
||
131 | * |
||
132 | * @param \Psr\Http\Message\ResponseInterface $response |
||
133 | * |
||
134 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
135 | */ |
||
136 | 12 | protected function prepareResponse(ResponseInterface $response) |
|
142 | |||
143 | /** |
||
144 | * Check the mode of transport. |
||
145 | * |
||
146 | * @param string $mode |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | 6 | private function checkMode($mode) |
|
163 | |||
164 | /** |
||
165 | * Check the unit system. |
||
166 | * |
||
167 | * @param string $units |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 6 | private function checkUnits($units) |
|
184 | } |
||
185 |