X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/76c146f3269ff07fdad66cb1d2d74c2acbc2af91..b01a836d1ecce5c7cc1aceedf19535eeda9058af:/lib-php/AddressDetails.php diff --git a/lib-php/AddressDetails.php b/lib-php/AddressDetails.php index a1a2a636..cfdd0416 100644 --- a/lib-php/AddressDetails.php +++ b/lib-php/AddressDetails.php @@ -93,8 +93,8 @@ class AddressDetails ) { $aAddress[$sTypeLabel] = $sName; - if ('state' === $sTypeLabel && !empty($aLine['name'])) { - $this->addStateCode($aAddress, $aLine['name']); + if (!empty($aLine['name'])) { + $this->addSubdivisionCode($aAddress, $aLine['admin_level'], $aLine['name']); } } } @@ -179,17 +179,13 @@ class AddressDetails return $this->aAddressLines; } - /** - * Add `state_code` field to address details to represent second part of ISO 3166-2 country subdivision code - */ - private function addStateCode(&$aAddress, $nameDetails) + private function addSubdivisionCode(&$aAddress, $iAdminLevel, $nameDetails) { if (is_string($nameDetails)) { $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true); } - - if (!empty($nameDetails['ref'])) { - $aAddress['state_code'] = $nameDetails['ref']; + if (!empty($nameDetails['ISO3166-2'])) { + $aAddress["ISO3166-2-lvl$iAdminLevel"] = $nameDetails['ISO3166-2']; } } }