1 | <?php namespace Arcanedev\GeoLocation\Google\DistanceMatrix; |
||
17 | class DistanceMatrixService extends AbstractService |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Constants |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | const BASE_URL = 'https://maps.googleapis.com/maps/api/distancematrix/json'; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Properties |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** @var string */ |
||
32 | protected $language = 'en'; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $mode = 'driving'; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $units = 'metric'; |
||
39 | |||
40 | /* ----------------------------------------------------------------- |
||
41 | | Constructor |
||
42 | | ----------------------------------------------------------------- |
||
43 | */ |
||
44 | |||
45 | /** |
||
46 | * GoogleDistanceMatrix constructor. |
||
47 | * |
||
48 | * @param \GuzzleHttp\ClientInterface $client |
||
49 | */ |
||
50 | 21 | public function __construct(ClientInterface $client) |
|
56 | |||
57 | /* ----------------------------------------------------------------- |
||
58 | | Getters & Setters |
||
59 | | ----------------------------------------------------------------- |
||
60 | */ |
||
61 | |||
62 | /** |
||
63 | * Set the language. |
||
64 | * |
||
65 | * @param string $language |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | 3 | public function setLanguage($language) |
|
75 | |||
76 | /** |
||
77 | * Set the mode of transport. |
||
78 | * |
||
79 | * @param string $mode |
||
80 | * |
||
81 | * @return self |
||
82 | */ |
||
83 | 6 | public function setMode($mode) |
|
89 | |||
90 | /** |
||
91 | * Set the unit system. |
||
92 | * |
||
93 | * @param string $units |
||
94 | * |
||
95 | * @return self |
||
96 | */ |
||
97 | 6 | public function setUnits($units) |
|
103 | |||
104 | /* ----------------------------------------------------------------- |
||
105 | | Main Methods |
||
106 | | ----------------------------------------------------------------- |
||
107 | */ |
||
108 | |||
109 | /** |
||
110 | * Calculate the distance. |
||
111 | * |
||
112 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $start |
||
113 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $end |
||
114 | * @param array $options |
||
115 | * |
||
116 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
117 | */ |
||
118 | 12 | public function calculate(Position $start, Position $end, array $options = []) |
|
127 | |||
128 | /* ----------------------------------------------------------------- |
||
129 | | Other Methods |
||
130 | | ----------------------------------------------------------------- |
||
131 | */ |
||
132 | |||
133 | /** |
||
134 | * Get the default query params. |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | 12 | protected function getDefaultQueryParams() |
|
147 | |||
148 | /** |
||
149 | * Prepare the response. |
||
150 | * |
||
151 | * @param \Psr\Http\Message\ResponseInterface $response |
||
152 | * |
||
153 | * @return \Arcanedev\GeoLocation\Google\DistanceMatrix\DistanceMatrixResponse |
||
154 | */ |
||
155 | 12 | protected function prepareResponse(ResponseInterface $response) |
|
161 | |||
162 | /** |
||
163 | * Check the mode of transport. |
||
164 | * |
||
165 | * @param string $mode |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 6 | private function checkMode($mode) |
|
182 | |||
183 | /** |
||
184 | * Check the unit system. |
||
185 | * |
||
186 | * @param string $units |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | 6 | private function checkUnits($units) |
|
203 | } |
||
204 |