From 6bee188f2412645360c303d80330b527482cf605 Mon Sep 17 00:00:00 2001 From: Artem Ziablytskyi Date: Wed, 26 Jan 2022 17:40:39 +0100 Subject: [PATCH] Change the key to `-ISO3166-2` to support xml response correctly --- docs/api/Output.md | 6 +++--- lib-php/AddressDetails.php | 9 +++------ test/php/Nominatim/AddressDetailsTest.php | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/api/Output.md b/docs/api/Output.md index d3ecf8d7..a584d251 100644 --- a/docs/api/Output.md +++ b/docs/api/Output.md @@ -28,7 +28,7 @@ a single place (for reverse) of the following format: "city": "London", "state_district": "Greater London", "state": "England", - "ISO3166-2": "GB-ENG", + "state-ISO3166-2": "GB-ENG", "postcode": "SW1A 2DU", "country": "United Kingdom", "country_code": "gb" @@ -181,7 +181,7 @@ Additional information requested with `addressdetails=1`, `extratags=1` and London Greater London England - ENG + GB-ENG SW1A 2DU United Kingdom gb @@ -282,7 +282,7 @@ with a designation label. Per default the following labels may appear: * continent * country, country_code - * region, state, state_code, state_district, county + * region, state, state-ISO3166-2, state_district, county, county-ISO3166-2 * municipality, city, town, village * city_district, district, borough, suburb, subdivision * hamlet, croft, isolated_dwelling diff --git a/lib-php/AddressDetails.php b/lib-php/AddressDetails.php index 657dc3e2..35786d22 100644 --- a/lib-php/AddressDetails.php +++ b/lib-php/AddressDetails.php @@ -94,7 +94,7 @@ class AddressDetails $aAddress[$sTypeLabel] = $sName; if (!empty($aLine['name'])) { - $this->addStateCode($aAddress, $sTypeLabel, $aLine['name']); + $this->addSubdivisionCode($aAddress, $sTypeLabel, $aLine['name']); } } } @@ -179,16 +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, $sTypeLabel, $nameDetails) + private function addSubdivisionCode(&$aAddress, $sTypeLabel, $nameDetails) { if (is_string($nameDetails)) { $nameDetails = json_decode('{' . str_replace('"=>"', '":"', $nameDetails) . '}', true); } if (!empty($nameDetails['ISO3166-2'])) { - $aAddress["$sTypeLabel:ISO3166-2"] = $nameDetails['ISO3166-2']; + $aAddress["$sTypeLabel-ISO3166-2"] = $nameDetails['ISO3166-2']; } } } diff --git a/test/php/Nominatim/AddressDetailsTest.php b/test/php/Nominatim/AddressDetailsTest.php index 02813286..42a51add 100644 --- a/test/php/Nominatim/AddressDetailsTest.php +++ b/test/php/Nominatim/AddressDetailsTest.php @@ -86,7 +86,7 @@ class AddressDetailsTest extends \PHPUnit\Framework\TestCase 'city' => 'London', 'state_district' => 'Greater London', 'state' => 'England', - 'state:ISO3166-2' => 'GB-ENG', + 'state-ISO3166-2' => 'GB-ENG', 'postcode' => 'SW1A 2AA', 'country' => 'United Kingdom', 'country_code' => 'gb' -- 2.39.5