forked from hans/Nominatim
add state_code field to response address details
This commit is contained in:
committed by
Sarah Hoffmann
parent
fd4ab3f262
commit
76c146f326
@@ -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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user