1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Service\Geocoder\Response; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderResult |
16
|
|
|
* |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class GeocoderResult |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
private $placeId; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var GeocoderAddress[] |
28
|
|
|
*/ |
29
|
|
|
private $addresses = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $formattedAddress; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string[] |
38
|
|
|
*/ |
39
|
|
|
private $postcodeLocalities = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var GeocoderGeometry|null |
43
|
|
|
*/ |
44
|
|
|
private $geometry; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var bool|null |
48
|
|
|
*/ |
49
|
|
|
private $partialMatch; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string[] |
53
|
|
|
*/ |
54
|
|
|
private $types = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function hasPlaceId() |
60
|
|
|
{ |
61
|
|
|
return $this->placeId !== null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string|null |
66
|
|
|
*/ |
67
|
|
|
public function getPlaceId() |
68
|
|
|
{ |
69
|
|
|
return $this->placeId; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string|null $placeId |
74
|
|
|
*/ |
75
|
|
|
public function setPlaceId($placeId) |
76
|
|
|
{ |
77
|
|
|
$this->placeId = $placeId; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string|null $type |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function hasAddresses($type = null) |
86
|
|
|
{ |
87
|
|
|
$addresses = $this->getAddresses($type); |
88
|
|
|
|
89
|
|
|
return !empty($addresses); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string|null $type |
94
|
|
|
* |
95
|
|
|
* @return GeocoderAddress[] |
96
|
|
|
*/ |
97
|
|
|
public function getAddresses($type = null) |
98
|
|
|
{ |
99
|
|
|
if ($type === null) { |
100
|
|
|
return $this->addresses; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$addresses = []; |
104
|
|
|
|
105
|
|
|
foreach ($this->addresses as $address) { |
106
|
|
|
if (in_array($type, $address->getTypes(), true)) { |
107
|
|
|
$addresses[] = $address; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $addresses; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param GeocoderAddress[] $addresses |
116
|
|
|
*/ |
117
|
|
|
public function setAddresses(array $addresses) |
118
|
|
|
{ |
119
|
|
|
$this->addresses = []; |
120
|
|
|
$this->addAddresses($addresses); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param GeocoderAddress[] $addresses |
125
|
|
|
*/ |
126
|
|
|
public function addAddresses(array $addresses) |
127
|
|
|
{ |
128
|
|
|
foreach ($addresses as $address) { |
129
|
|
|
$this->addAddress($address); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param GeocoderAddress $address |
135
|
|
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function hasAddress(GeocoderAddress $address) |
139
|
|
|
{ |
140
|
|
|
return in_array($address, $this->addresses, true); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param GeocoderAddress $address |
145
|
|
|
*/ |
146
|
|
|
public function addAddress(GeocoderAddress $address) |
147
|
|
|
{ |
148
|
|
|
if (!$this->hasAddress($address)) { |
149
|
|
|
$this->addresses[] = $address; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param GeocoderAddress $address |
155
|
|
|
*/ |
156
|
|
|
public function removeAddress(GeocoderAddress $address) |
157
|
|
|
{ |
158
|
|
|
unset($this->addresses[array_search($address, $this->addresses, true)]); |
159
|
|
|
$this->addresses = array_values($this->addresses); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
|
|
public function hasFormattedAddress() |
166
|
|
|
{ |
167
|
|
|
return !empty($this->formattedAddress); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string|null |
172
|
|
|
*/ |
173
|
|
|
public function getFormattedAddress() |
174
|
|
|
{ |
175
|
|
|
return $this->formattedAddress; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string|null $formattedAddress |
180
|
|
|
*/ |
181
|
|
|
public function setFormattedAddress($formattedAddress = null) |
182
|
|
|
{ |
183
|
|
|
$this->formattedAddress = $formattedAddress; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function hasPostcodeLocalities() |
190
|
|
|
{ |
191
|
|
|
return !empty($this->postcodeLocalities); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string[] |
196
|
|
|
*/ |
197
|
|
|
public function getPostcodeLocalities() |
198
|
|
|
{ |
199
|
|
|
return $this->postcodeLocalities; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string[] $postcodeLocalities |
204
|
|
|
*/ |
205
|
|
|
public function setPostcodeLocalities(array $postcodeLocalities) |
206
|
|
|
{ |
207
|
|
|
$this->postcodeLocalities = []; |
208
|
|
|
$this->addPostcodeLocalities($postcodeLocalities); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @param string[] $postcodeLocalities |
213
|
|
|
*/ |
214
|
|
|
public function addPostcodeLocalities(array $postcodeLocalities) |
215
|
|
|
{ |
216
|
|
|
foreach ($postcodeLocalities as $postcodeLocality) { |
217
|
|
|
$this->addPostcodeLocality($postcodeLocality); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param string $postcodeLocality |
223
|
|
|
* |
224
|
|
|
* @return bool |
225
|
|
|
*/ |
226
|
|
|
public function hasPostcodeLocality($postcodeLocality) |
227
|
|
|
{ |
228
|
|
|
return in_array($postcodeLocality, $this->postcodeLocalities, true); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @param string $postcodeLocality |
233
|
|
|
*/ |
234
|
|
|
public function addPostcodeLocality($postcodeLocality) |
235
|
|
|
{ |
236
|
|
|
if (!$this->hasPostcodeLocality($postcodeLocality)) { |
237
|
|
|
$this->postcodeLocalities[] = $postcodeLocality; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param string $postcodeLocality |
243
|
|
|
*/ |
244
|
|
|
public function removePostcodeLocality($postcodeLocality) |
245
|
|
|
{ |
246
|
|
|
unset($this->postcodeLocalities[array_search($postcodeLocality, $this->postcodeLocalities, true)]); |
247
|
|
|
$this->postcodeLocalities = array_values($this->postcodeLocalities); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return bool |
252
|
|
|
*/ |
253
|
|
|
public function hasGeometry() |
254
|
|
|
{ |
255
|
|
|
return $this->geometry !== null; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return GeocoderGeometry|null |
260
|
|
|
*/ |
261
|
|
|
public function getGeometry() |
262
|
|
|
{ |
263
|
|
|
return $this->geometry; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param GeocoderGeometry|null $geometry |
268
|
|
|
*/ |
269
|
|
|
public function setGeometry(GeocoderGeometry $geometry = null) |
270
|
|
|
{ |
271
|
|
|
$this->geometry = $geometry; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return bool |
276
|
|
|
*/ |
277
|
|
|
public function hasPartialMatch() |
278
|
|
|
{ |
279
|
|
|
return $this->partialMatch !== null; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return bool |
284
|
|
|
*/ |
285
|
|
|
public function isPartialMatch() |
286
|
|
|
{ |
287
|
|
|
return $this->partialMatch; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param bool|null $partialMatch |
292
|
|
|
*/ |
293
|
|
|
public function setPartialMatch($partialMatch = null) |
294
|
|
|
{ |
295
|
|
|
$this->partialMatch = $partialMatch; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return bool |
300
|
|
|
*/ |
301
|
|
|
public function hasTypes() |
302
|
|
|
{ |
303
|
|
|
return !empty($this->types); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return string[] |
308
|
|
|
*/ |
309
|
|
|
public function getTypes() |
310
|
|
|
{ |
311
|
|
|
return $this->types; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param string[] $types |
316
|
|
|
*/ |
317
|
|
|
public function setTypes(array $types) |
318
|
|
|
{ |
319
|
|
|
$this->types = []; |
320
|
|
|
$this->addTypes($types); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param string[] $types |
325
|
|
|
*/ |
326
|
|
|
public function addTypes(array $types) |
327
|
|
|
{ |
328
|
|
|
foreach ($types as $type) { |
329
|
|
|
$this->addType($type); |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @param string $type |
335
|
|
|
* |
336
|
|
|
* @return bool |
337
|
|
|
*/ |
338
|
|
|
public function hasType($type) |
339
|
|
|
{ |
340
|
|
|
return in_array($type, $this->types, true); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @param string $type |
345
|
|
|
*/ |
346
|
|
|
public function addType($type) |
347
|
|
|
{ |
348
|
|
|
if (!$this->hasType($type)) { |
349
|
|
|
$this->types[] = $type; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @param string $type |
355
|
|
|
*/ |
356
|
|
|
public function removeType($type) |
357
|
|
|
{ |
358
|
|
|
unset($this->types[array_search($type, $this->types, true)]); |
359
|
|
|
$this->types = array_values($this->types); |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|