]> git.openstreetmap.org Git - nominatim.git/commitdiff
add `state_code` field to response address details
authorArtem Ziablytskyi <a.ziablytskyi@sportradar.com>
Tue, 12 Oct 2021 15:35:15 +0000 (17:35 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 7 Apr 2022 14:37:51 +0000 (16:37 +0200)
docs/api/Output.md
lib-php/AddressDetails.php
test/php/Nominatim/AddressDetailsTest.php
test/php/fixtures/address_details_10_downing_street.json

index 31dd5b3f5206850e6a64aca67b2110cdaab17874..3c541d33afe18c51c09bf88ac9b54e78431b3210 100644 (file)
@@ -28,6 +28,7 @@ a single place (for reverse) of the following format:
       "city": "London",
       "state_district": "Greater London",
       "state": "England",
+      "state_code": "ENG",
       "postcode": "SW1A 2DU",
       "country": "United Kingdom",
       "country_code": "gb"
@@ -126,6 +127,7 @@ formats depending on the API call.
   </result>
   <addressparts>
      <state>Bavaria</state>
+     <state_code>BY</state_code>
      <country>Germany</country>
      <country_code>de</country_code>
   </addressparts>
@@ -179,6 +181,7 @@ Additional information requested with `addressdetails=1`, `extratags=1` and
     <city>London</city>
     <state_district>Greater London</state_district>
     <state>England</state>
+    <state_code>ENG</state_code>
     <postcode>SW1A 2DU</postcode>
     <country>United Kingdom</country>
     <country_code>gb</country_code>
@@ -279,7 +282,7 @@ with a designation label. Per default the following labels may appear:
 
  * continent
  * country, country_code
- * region, state, state_district, county
+ * region, state, state_code, state_district, county
  * municipality, city, town, village
  * city_district, district, borough, suburb, subdivision
  * hamlet, croft, isolated_dwelling
index 1bd475ad268427377b1d7f24676dad46bf2ce5b8..a1a2a636156e686843b4fcebc46f5a236383a85a 100644 (file)
@@ -92,6 +92,10 @@ class AddressDetails
                     || $aLine['class'] == 'place')
             ) {
                 $aAddress[$sTypeLabel] = $sName;
+
+                if ('state' === $sTypeLabel && !empty($aLine['name'])) {
+                    $this->addStateCode($aAddress, $aLine['name']);
+                }
             }
         }
 
@@ -174,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'];
+        }
+    }
 }
index 1425be2d4f6305c5ec9a9d5c372e5fa6dba4570e..4cf363448b3e8fd50ec126ea4635528d054485b9 100644 (file)
@@ -86,6 +86,7 @@ class AddressDetailsTest extends \PHPUnit\Framework\TestCase
                      'city' => 'London',
                      'state_district' => 'Greater London',
                      'state' => 'England',
+                     'state_code' => 'ENG',
                      'postcode' => 'SW1A 2AA',
                      'country' => 'United Kingdom',
                      'country_code' => 'gb'
index 853a6c0780d54f1fc8a37b6572efe24f8881ab55..f56cfd9a6ab7f7614ec77280ed8ad6a682e9d4d3 100644 (file)
 {"place_id":194325361,
  "osm_type":"R",
  "osm_id":58447,
- "name":{"name": "England", "name:be": "Англія", "name:br": "Bro-Saoz", "name:ca": "Anglaterra", "name:cs": "Anglie", "name:cy": "Lloegr", "name:de": "England", "name:el": "Αγγλία", "name:en": "England", "name:eo": "Anglujo", "name:es": "Inglaterra", "name:fi": "Englanti", "name:fr": "Angleterre", "name:fy": "Ingelân", "name:ga": "Sasana", "name:gd": "Sasainn", "name:gv": "Sostyn", "name:he": "אנגליה", "name:hu": "Anglia", "name:ia": "Anglaterra", "name:io": "Anglia", "name:it": "Inghilterra", "name:la": "Anglia", "name:lt": "Anglija", "name:nl": "Engeland", "name:pl": "Anglia", "name:pt": "Inglaterra", "name:ru": "Англия", "name:sk": "Anglicko", "name:sv": "England", "name:tr": "İngiltere", "name:uk": "Англія", "name:vi": "Anh", "name:vo": "Linglän", "name:zh": "英格蘭", "name:hsb": "Jendźelska", "name:nds": "England", "name:tok": "ma Inli", "name:tzl": "Anglatzara", "alt_name:eo": "Anglio", "alt_name:ia": "Anglia", "old_name:vi": "Anh Quốc", "alt_name:nds": "Ingland", "name:be-tarask": "Ангельшчына", "name:zh-classical": "英格蘭", "name:zh-simplified": "英格兰", "name:zh-traditional": "英格蘭"},
+ "name":{"ref": "ENG", "name": "England", "name:be": "Англія", "name:br": "Bro-Saoz", "name:ca": "Anglaterra", "name:cs": "Anglie", "name:cy": "Lloegr", "name:de": "England", "name:el": "Αγγλία", "name:en": "England", "name:eo": "Anglujo", "name:es": "Inglaterra", "name:fi": "Englanti", "name:fr": "Angleterre", "name:fy": "Ingelân", "name:ga": "Sasana", "name:gd": "Sasainn", "name:gv": "Sostyn", "name:he": "אנגליה", "name:hu": "Anglia", "name:ia": "Anglaterra", "name:io": "Anglia", "name:it": "Inghilterra", "name:la": "Anglia", "name:lt": "Anglija", "name:nl": "Engeland", "name:pl": "Anglia", "name:pt": "Inglaterra", "name:ru": "Англия", "name:sk": "Anglicko", "name:sv": "England", "name:tr": "İngiltere", "name:uk": "Англія", "name:vi": "Anh", "name:vo": "Linglän", "name:zh": "英格蘭", "name:hsb": "Jendźelska", "name:nds": "England", "name:tok": "ma Inli", "name:tzl": "Anglatzara", "alt_name:eo": "Anglio", "alt_name:ia": "Anglia", "old_name:vi": "Anh Quốc", "alt_name:nds": "Ingland", "name:be-tarask": "Ангельшчына", "name:zh-classical": "英格蘭", "name:zh-simplified": "英格兰", "name:zh-traditional": "英格蘭"},
  "class":"boundary",
  "type":"administrative",
  "admin_level":4,
  "rank_address":4,
  "distance":0,
  "localname":"gb"}
-]
\ No newline at end of file
+]