1 | <?php namespace Arcanedev\GeoLocation\Google\Directions; |
||
16 | class DirectionsService extends AbstractService |
||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Constants |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | const BASE_URL = 'https://maps.googleapis.com/maps/api/directions/json'; |
||
24 | |||
25 | /* ----------------------------------------------------------------- |
||
26 | | Properties |
||
27 | | ----------------------------------------------------------------- |
||
28 | */ |
||
29 | |||
30 | /** |
||
31 | * Start point. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $origin; |
||
36 | |||
37 | /** |
||
38 | * End point. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $destination; |
||
43 | |||
44 | /* ----------------------------------------------------------------- |
||
45 | | Constructor |
||
46 | | ----------------------------------------------------------------- |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * DirectionsService constructor. |
||
51 | * |
||
52 | * @param \GuzzleHttp\ClientInterface $client |
||
53 | */ |
||
54 | 15 | public function __construct(ClientInterface $client) |
|
60 | |||
61 | /* ----------------------------------------------------------------- |
||
62 | | Getters & Setters |
||
63 | | ----------------------------------------------------------------- |
||
64 | */ |
||
65 | |||
66 | /** |
||
67 | * Set the start point. |
||
68 | * |
||
69 | * @param string $origin |
||
70 | * |
||
71 | * @return self |
||
72 | */ |
||
73 | 12 | public function setOrigin($origin) |
|
79 | |||
80 | /** |
||
81 | * Set the origin point with an address (alias). |
||
82 | * |
||
83 | * @param string $address |
||
84 | * |
||
85 | * @return self |
||
86 | */ |
||
87 | 3 | public function from($address) |
|
91 | |||
92 | /** |
||
93 | * Set the origin point with position object. |
||
94 | * |
||
95 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $position |
||
96 | * |
||
97 | * @return self |
||
98 | */ |
||
99 | 3 | public function fromPosition(Position $position) |
|
106 | |||
107 | /** |
||
108 | * Set the origin point with coordinates. |
||
109 | * |
||
110 | * @param float $lat |
||
111 | * @param float $long |
||
112 | * |
||
113 | * @return self |
||
114 | */ |
||
115 | 6 | public function fromCoordinates($lat, $long) |
|
119 | |||
120 | /** |
||
121 | * Set the origin point with place id. |
||
122 | * |
||
123 | * @param string $placeId |
||
124 | * |
||
125 | * @return self |
||
126 | */ |
||
127 | 3 | public function fromPlace($placeId) |
|
131 | |||
132 | /** |
||
133 | * Set the end point. |
||
134 | * |
||
135 | * @param string $destination |
||
136 | * |
||
137 | * @return self |
||
138 | */ |
||
139 | 12 | public function setDestination($destination) |
|
145 | |||
146 | /** |
||
147 | * Set the destination point with an address. |
||
148 | * |
||
149 | * @param string $address |
||
150 | * |
||
151 | * @return self |
||
152 | */ |
||
153 | 3 | public function to($address) |
|
157 | |||
158 | /** |
||
159 | * Set the destination point with position object. |
||
160 | * |
||
161 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Coordinates\Position $position |
||
162 | * |
||
163 | * @return self |
||
164 | */ |
||
165 | 3 | public function toPosition(Position $position) |
|
172 | |||
173 | /** |
||
174 | * Set the destination point with coordinates. |
||
175 | * |
||
176 | * @param float $lat |
||
177 | * @param float $long |
||
178 | * |
||
179 | * @return self |
||
180 | */ |
||
181 | 6 | public function toCoordinates($lat, $long) |
|
185 | |||
186 | /** |
||
187 | * Set the destination point with place id. |
||
188 | * |
||
189 | * @param string $placeId |
||
190 | * |
||
191 | * @return self |
||
192 | */ |
||
193 | 3 | public function toPlace($placeId) |
|
197 | |||
198 | /* ----------------------------------------------------------------- |
||
199 | | Main Methods |
||
200 | | ----------------------------------------------------------------- |
||
201 | */ |
||
202 | |||
203 | /** |
||
204 | * Get the directions. |
||
205 | * |
||
206 | * @param array $options |
||
207 | * |
||
208 | * @return \Arcanedev\GeoLocation\Google\Directions\DirectionsResponse |
||
209 | */ |
||
210 | 12 | public function directions(array $options = []) |
|
219 | |||
220 | /* ----------------------------------------------------------------- |
||
221 | | Other Methods |
||
222 | | ----------------------------------------------------------------- |
||
223 | */ |
||
224 | |||
225 | /** |
||
226 | * Get the default query params. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | 12 | protected function getDefaultQueryParams() |
|
236 | |||
237 | /** |
||
238 | * Prepare the response. |
||
239 | * |
||
240 | * @param \Psr\Http\Message\ResponseInterface $response |
||
241 | * |
||
242 | * @return \Arcanedev\GeoLocation\Google\Directions\DirectionsResponse |
||
243 | */ |
||
244 | 12 | protected function prepareResponse(ResponseInterface $response) |
|
250 | } |
||
251 |