Skip to content

Commit 775a114

Browse files
author
Sébastien
committed
NominatimProvider: get locality from city, then town, then village, then hamlet
1 parent 81a6bda commit 775a114

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

src/Provider/GoogleMaps/Model/GoogleAddress.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ final class GoogleAddress extends Address
116116
*
117117
* @return GoogleAddress
118118
*/
119-
public function withId(string $id = null): GoogleAddress
119+
public function withId(string $id = null): self
120120
{
121121
$new = clone $this;
122122
$new->id = $id;
@@ -139,7 +139,7 @@ public function getId()
139139
*
140140
* @return GoogleAddress
141141
*/
142-
public function withLocationType(string $locationType = null): GoogleAddress
142+
public function withLocationType(string $locationType = null): self
143143
{
144144
$new = clone $this;
145145
$new->locationType = $locationType;
@@ -168,7 +168,7 @@ public function getResultType(): array
168168
*
169169
* @return GoogleAddress
170170
*/
171-
public function withResultType(array $resultType): GoogleAddress
171+
public function withResultType(array $resultType): self
172172
{
173173
$new = clone $this;
174174
$new->resultType = $resultType;
@@ -189,7 +189,7 @@ public function getFormattedAddress()
189189
*
190190
* @return GoogleAddress
191191
*/
192-
public function withFormattedAddress(string $formattedAddress = null): GoogleAddress
192+
public function withFormattedAddress(string $formattedAddress = null): self
193193
{
194194
$new = clone $this;
195195
$new->formattedAddress = $formattedAddress;
@@ -210,7 +210,7 @@ public function getAirport()
210210
*
211211
* @return GoogleAddress
212212
*/
213-
public function withAirport(string $airport = null): GoogleAddress
213+
public function withAirport(string $airport = null): self
214214
{
215215
$new = clone $this;
216216
$new->airport = $airport;
@@ -231,7 +231,7 @@ public function getColloquialArea()
231231
*
232232
* @return GoogleAddress
233233
*/
234-
public function withColloquialArea(string $colloquialArea = null): GoogleAddress
234+
public function withColloquialArea(string $colloquialArea = null): self
235235
{
236236
$new = clone $this;
237237
$new->colloquialArea = $colloquialArea;
@@ -252,7 +252,7 @@ public function getIntersection()
252252
*
253253
* @return GoogleAddress
254254
*/
255-
public function withIntersection(string $intersection = null): GoogleAddress
255+
public function withIntersection(string $intersection = null): self
256256
{
257257
$new = clone $this;
258258
$new->intersection = $intersection;
@@ -273,7 +273,7 @@ public function getNaturalFeature()
273273
*
274274
* @return GoogleAddress
275275
*/
276-
public function withNaturalFeature(string $naturalFeature = null): GoogleAddress
276+
public function withNaturalFeature(string $naturalFeature = null): self
277277
{
278278
$new = clone $this;
279279
$new->naturalFeature = $naturalFeature;
@@ -294,7 +294,7 @@ public function getNeighborhood()
294294
*
295295
* @return GoogleAddress
296296
*/
297-
public function withNeighborhood(string $neighborhood = null): GoogleAddress
297+
public function withNeighborhood(string $neighborhood = null): self
298298
{
299299
$new = clone $this;
300300
$new->neighborhood = $neighborhood;
@@ -315,7 +315,7 @@ public function getPark()
315315
*
316316
* @return GoogleAddress
317317
*/
318-
public function withPark(string $park = null): GoogleAddress
318+
public function withPark(string $park = null): self
319319
{
320320
$new = clone $this;
321321
$new->park = $park;
@@ -357,7 +357,7 @@ public function getPolitical()
357357
*
358358
* @return GoogleAddress
359359
*/
360-
public function withPolitical(string $political = null): GoogleAddress
360+
public function withPolitical(string $political = null): self
361361
{
362362
$new = clone $this;
363363
$new->political = $political;
@@ -378,7 +378,7 @@ public function getPremise()
378378
*
379379
* @return GoogleAddress
380380
*/
381-
public function withPremise(string $premise = null): GoogleAddress
381+
public function withPremise(string $premise = null): self
382382
{
383383
$new = clone $this;
384384
$new->premise = $premise;
@@ -399,7 +399,7 @@ public function getStreetAddress()
399399
*
400400
* @return GoogleAddress
401401
*/
402-
public function withStreetAddress(string $streetAddress = null): GoogleAddress
402+
public function withStreetAddress(string $streetAddress = null): self
403403
{
404404
$new = clone $this;
405405
$new->streetAddress = $streetAddress;
@@ -420,7 +420,7 @@ public function getSubpremise()
420420
*
421421
* @return GoogleAddress
422422
*/
423-
public function withSubpremise(string $subpremise = null): GoogleAddress
423+
public function withSubpremise(string $subpremise = null): self
424424
{
425425
$new = clone $this;
426426
$new->subpremise = $subpremise;
@@ -441,7 +441,7 @@ public function getWard()
441441
*
442442
* @return GoogleAddress
443443
*/
444-
public function withWard(string $ward = null): GoogleAddress
444+
public function withWard(string $ward = null): self
445445
{
446446
$new = clone $this;
447447
$new->ward = $ward;
@@ -462,7 +462,7 @@ public function getEstablishment()
462462
*
463463
* @return GoogleAddress
464464
*/
465-
public function withEstablishment(string $establishment = null): GoogleAddress
465+
public function withEstablishment(string $establishment = null): self
466466
{
467467
$new = clone $this;
468468
$new->establishment = $establishment;
@@ -483,7 +483,7 @@ public function getSubLocalityLevels(): AdminLevelCollection
483483
*
484484
* @return $this
485485
*/
486-
public function withSubLocalityLevels(array $subLocalityLevel): GoogleAddress
486+
public function withSubLocalityLevels(array $subLocalityLevel): self
487487
{
488488
$subLocalityLevels = [];
489489
foreach ($subLocalityLevel as $level) {

src/Provider/Nominatim/Nominatim.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,20 @@ private function xmlResultToArray(\DOMElement $resultNode, \DOMElement $addressN
138138
if (!empty($postalCode)) {
139139
$postalCode = current(explode(';', $postalCode));
140140
}
141+
142+
$localityFields = ['city', 'town', 'village', 'hamlet'];
143+
foreach ($localityFields as $localityField) {
144+
$localityFieldContent = $this->getNodeValue($addressNode->getElementsByTagName($localityField));
145+
if (!empty($localityFieldContent)) {
146+
$builder->setLocality($localityFieldContent);
147+
148+
break;
149+
}
150+
}
151+
141152
$builder->setPostalCode($postalCode);
142153
$builder->setStreetName($this->getNodeValue($addressNode->getElementsByTagName('road')) ?: $this->getNodeValue($addressNode->getElementsByTagName('pedestrian')));
143154
$builder->setStreetNumber($this->getNodeValue($addressNode->getElementsByTagName('house_number')));
144-
$builder->setLocality($this->getNodeValue($addressNode->getElementsByTagName('city')));
145155
$builder->setSubLocality($this->getNodeValue($addressNode->getElementsByTagName('suburb')));
146156
$builder->setCountry($this->getNodeValue($addressNode->getElementsByTagName('country')));
147157

0 commit comments

Comments
 (0)