1 | <?php namespace Arcanedev\GeoLocation\Google\DistanceMatrix; |
||
16 | class DistanceMatrixService extends AbstractWebService |
||
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 | | Constructor |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * GoogleDistanceMatrix constructor. |
||
46 | * |
||
47 | * @param \GuzzleHttp\ClientInterface $client |
||
48 | */ |
||
49 | 21 | public function __construct(ClientInterface $client) |
|
55 | |||
56 | /* ----------------------------------------------------------------- |
||
57 | | Getters & Setters |
||
58 | | ----------------------------------------------------------------- |
||
59 | */ |
||
60 | |||
61 | /** |
||
62 | * Set the language. |
||
63 | * |
||
64 | * @param string $language |
||
65 | * |
||
66 | * @return self |
||
67 | */ |
||
68 | 3 | public function setLanguage($language) |
|
74 | |||
75 | /** |
||
76 | * Set the mode of transport. |
||
77 | * |
||
78 | * @param string $mode |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | 6 | public function setMode($mode) |
|
88 | |||
89 | /** |
||
90 | * Set the unit system. |
||
91 | * |
||
92 | * @param string $units |
||
93 | * |
||
94 | * @return self |
||
95 | */ |
||
96 | 6 | public function setUnits($units) |
|
102 | |||
103 | /* ----------------------------------------------------------------- |
||
104 | | Main Methods |
||
105 | | ----------------------------------------------------------------- |
||
106 | */ |
||
107 | |||
108 | /** |
||
109 | * Calculate the distance. |
||
110 | * |
||
111 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Position $start |
||
112 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Position $end |
||
113 | * @param array $options |
||
114 | * |
||
115 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
116 | */ |
||
117 | 12 | public function calculate(Position $start, Position $end, array $options = []) |
|
128 | |||
129 | /* ----------------------------------------------------------------- |
||
130 | | Other Methods |
||
131 | | ----------------------------------------------------------------- |
||
132 | */ |
||
133 | |||
134 | /** |
||
135 | * Get the default query params. |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 12 | protected function getDefaultQueryParams() |
|
148 | |||
149 | /** |
||
150 | * Prepare the response. |
||
151 | * |
||
152 | * @param \Psr\Http\Message\ResponseInterface $response |
||
153 | * |
||
154 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
155 | */ |
||
156 | 12 | private function prepareResponse($response) |
|
162 | |||
163 | /** |
||
164 | * Check the mode of transport. |
||
165 | * |
||
166 | * @param string $mode |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | 6 | private function checkMode($mode) |
|
183 | |||
184 | /** |
||
185 | * Check the unit system. |
||
186 | * |
||
187 | * @param string $units |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | 6 | private function checkUnits($units) |
|
204 | } |
||
205 |