forked from geocoder-php/php-common
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddress.php
More file actions
268 lines (238 loc) · 5.48 KB
/
Copy pathAddress.php
File metadata and controls
268 lines (238 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Geocoder\Model;
/**
* @author William Durand <[email protected]>
*/
final class Address
{
/**
* @var Coordinates
*/
private $coordinates;
/**
* @var Bounds
*/
private $bounds;
/**
* @var string|int
*/
private $streetNumber;
/**
* @var string
*/
private $streetName;
/**
* @var string
*/
private $subLocality;
/**
* @var string
*/
private $locality;
/**
* @var string
*/
private $postalCode;
/**
* @var AdminLevelCollection
*/
private $adminLevels;
/**
* @var Country
*/
private $country;
/**
* @var string
*/
private $timezone;
/**
* @param string $streetNumber
* @param string $streetName
* @param string $postalCode
* @param string $locality
* @param string $subLocality
*/
public function __construct(
Coordinates $coordinates = null,
Bounds $bounds = null,
$streetNumber = null,
$streetName = null,
$postalCode = null,
$locality = null,
$subLocality = null,
AdminLevelCollection $adminLevels = null,
Country $country = null,
$timezone = null
) {
$this->coordinates = $coordinates;
$this->bounds = $bounds;
$this->streetNumber = $streetNumber;
$this->streetName = $streetName;
$this->postalCode = $postalCode;
$this->locality = $locality;
$this->subLocality = $subLocality;
$this->adminLevels = $adminLevels ?: new AdminLevelCollection();
$this->country = $country;
$this->timezone = $timezone;
}
/**
* Returns an array of coordinates (latitude, longitude).
*
* @return Coordinates
*/
public function getCoordinates()
{
return $this->coordinates;
}
/**
* Returns the latitude value.
*
* @return double
*/
public function getLatitude()
{
if (null === $this->coordinates) {
return null;
}
return $this->coordinates->getLatitude();
}
/**
* Returns the longitude value.
*
* @return double
*/
public function getLongitude()
{
if (null === $this->coordinates) {
return null;
}
return $this->coordinates->getLongitude();
}
/**
* Returns the bounds value.
*
* @return Bounds
*/
public function getBounds()
{
return $this->bounds;
}
/**
* Returns the street number value.
*
* @return string|int
*/
public function getStreetNumber()
{
return $this->streetNumber;
}
/**
* Returns the street name value.
*
* @return string
*/
public function getStreetName()
{
return $this->streetName;
}
/**
* Returns the city or locality value.
*
* @return string
*/
public function getLocality()
{
return $this->locality;
}
/**
* Returns the postal code or zipcode value.
*
* @return string
*/
public function getPostalCode()
{
return $this->postalCode;
}
/**
* Returns the locality district, or
* sublocality, or neighborhood.
*
* @return string
*/
public function getSubLocality()
{
return $this->subLocality;
}
/**
* Returns the administrative levels.
*
* @return AdminLevelCollection
*/
public function getAdminLevels()
{
return $this->adminLevels;
}
/**
* Returns the country value.
*
* @return Country
*/
public function getCountry()
{
return $this->country;
}
/**
* Returns the country ISO code.
*
* @return string
*/
public function getCountryCode()
{
return $this->country->getCode();
}
/**
* Returns the timezone.
*
* @return string
*/
public function getTimezone()
{
return $this->timezone;
}
/**
* Returns an array with data indexed by name.
*
* @return array
*/
public function toArray()
{
$adminLevels = [];
foreach ($this->adminLevels as $adminLevel) {
$adminLevels[$adminLevel->getLevel()] = [
'name' => $adminLevel->getName(),
'code' => $adminLevel->getCode()
];
}
return array(
'latitude' => $this->getLatitude(),
'longitude' => $this->getLongitude(),
'bounds' => $this->bounds->toArray(),
'streetNumber' => $this->streetNumber,
'streetName' => $this->streetName,
'postalCode' => $this->postalCode,
'locality' => $this->locality,
'subLocality' => $this->subLocality,
'adminLevels' => $adminLevels,
'country' => $this->country->getName(),
'countryCode' => $this->country->getCode(),
'timezone' => $this->timezone,
);
}
}