]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib-php/AddressDetails.php
Merge pull request #3248 from lonvia/fix-postcode-area-computation
[nominatim.git] / lib-php / AddressDetails.php
index 1bd475ad268427377b1d7f24676dad46bf2ce5b8..cfdd04167c259de142147e00846ff1b9546fd8e7 100644 (file)
@@ -92,6 +92,10 @@ class AddressDetails
                     || $aLine['class'] == 'place')
             ) {
                 $aAddress[$sTypeLabel] = $sName;
+
+                if (!empty($aLine['name'])) {
+                    $this->addSubdivisionCode($aAddress, $aLine['admin_level'], $aLine['name']);
+                }
             }
         }
 
@@ -174,4 +178,14 @@ class AddressDetails
     {
         return $this->aAddressLines;
     }
+
+    private function addSubdivisionCode(&$aAddress, $iAdminLevel, $nameDetails)
+    {
+        if (is_string($nameDetails)) {
+            $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true);
+        }
+        if (!empty($nameDetails['ISO3166-2'])) {
+            $aAddress["ISO3166-2-lvl$iAdminLevel"] = $nameDetails['ISO3166-2'];
+        }
+    }
 }