X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/500c61685b16fd1d51e7b5f4738c788a9d00eab4..76c146f3269ff07fdad66cb1d2d74c2acbc2af91:/lib-php/AddressDetails.php?ds=sidebyside diff --git a/lib-php/AddressDetails.php b/lib-php/AddressDetails.php index fc7fbec7..a1a2a636 100644 --- a/lib-php/AddressDetails.php +++ b/lib-php/AddressDetails.php @@ -1,4 +1,12 @@ addStateCode($aAddress, $aLine['name']); } } } @@ -167,4 +178,18 @@ 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) + { + if (is_string($nameDetails)) { + $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true); + } + + if (!empty($nameDetails['ref'])) { + $aAddress['state_code'] = $nameDetails['ref']; + } + } }