1 | <?php namespace Arcanedev\GeoLocation\Google\Directions; |
||
13 | class DirectionsService extends AbstractService |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Constants |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | const BASE_URL = 'https://maps.googleapis.com/maps/api/directions/json'; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Properties |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Start point. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $origin; |
||
33 | |||
34 | /** |
||
35 | * End point. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $destination; |
||
40 | |||
41 | /* ----------------------------------------------------------------- |
||
42 | | Getters & Setters |
||
43 | | ----------------------------------------------------------------- |
||
44 | */ |
||
45 | |||
46 | /** |
||
47 | * Set the start point. |
||
48 | * |
||
49 | * @param string $origin |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | public function setOrigin($origin) |
||
59 | |||
60 | /** |
||
61 | * Set the origin point with an address (alias). |
||
62 | * |
||
63 | * @param string $address |
||
64 | * |
||
65 | * @return self |
||
66 | */ |
||
67 | public function from($address) |
||
71 | |||
72 | /** |
||
73 | * Set the origin point with position object. |
||
74 | * |
||
75 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Position $position |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | public function fromPosition(Position $position) |
||
86 | |||
87 | /** |
||
88 | * Set the origin point with coordinates. |
||
89 | * |
||
90 | * @param float $lat |
||
91 | * @param float $long |
||
92 | * |
||
93 | * @return self |
||
94 | */ |
||
95 | public function fromCoordinates($lat, $long) |
||
99 | |||
100 | /** |
||
101 | * Set the origin point with place id. |
||
102 | * |
||
103 | * @param string $placeId |
||
104 | * |
||
105 | * @return self |
||
106 | */ |
||
107 | public function fromPlace($placeId) |
||
111 | |||
112 | /** |
||
113 | * Set the end point. |
||
114 | * |
||
115 | * @param string $destination |
||
116 | * |
||
117 | * @return self |
||
118 | */ |
||
119 | public function setDestination($destination) |
||
125 | |||
126 | /** |
||
127 | * Set the destination point with an address. |
||
128 | * |
||
129 | * @param string $address |
||
130 | * |
||
131 | * @return self |
||
132 | */ |
||
133 | public function to($address) |
||
137 | |||
138 | /** |
||
139 | * Set the destination point with position object. |
||
140 | * |
||
141 | * @param \Arcanedev\GeoLocation\Contracts\Entities\Position $position |
||
142 | * |
||
143 | * @return self |
||
144 | */ |
||
145 | public function toPosition(Position $position) |
||
152 | |||
153 | /** |
||
154 | * Set the destination point with coordinates. |
||
155 | * |
||
156 | * @param float $lat |
||
157 | * @param float $long |
||
158 | * |
||
159 | * @return self |
||
160 | */ |
||
161 | public function toCoordinates($lat, $long) |
||
165 | |||
166 | /** |
||
167 | * Set the destination point with place id. |
||
168 | * |
||
169 | * @param string $placeId |
||
170 | * |
||
171 | * @return self |
||
172 | */ |
||
173 | public function toPlace($placeId) |
||
177 | |||
178 | /* ----------------------------------------------------------------- |
||
179 | | Main Methods |
||
180 | | ----------------------------------------------------------------- |
||
181 | */ |
||
182 | |||
183 | /** |
||
184 | * Get the directions. |
||
185 | * |
||
186 | * @param array $options |
||
187 | * |
||
188 | * @return \Arcanedev\GeoLocation\Google\Directions\DirectionsResponse |
||
189 | */ |
||
190 | public function directions(array $options = []) |
||
199 | |||
200 | /* ----------------------------------------------------------------- |
||
201 | | Other Methods |
||
202 | | ----------------------------------------------------------------- |
||
203 | */ |
||
204 | |||
205 | /** |
||
206 | * Get the default query params. |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | protected function getDefaultQueryParams() |
||
216 | |||
217 | /** |
||
218 | * Prepare the response. |
||
219 | * |
||
220 | * @param \Psr\Http\Message\ResponseInterface $response |
||
221 | * |
||
222 | * @return \Arcanedev\GeoLocation\Google\Directions\DirectionsResponse |
||
223 | */ |
||
224 | protected function prepareResponse(ResponseInterface $response) |
||
230 | } |
||
231 |