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