mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-11 13:24:07 +00:00
factor out geocodejson address generation
Unifies the two implementations currently used for search and address.
This commit is contained in:
@@ -101,6 +101,28 @@ class AddressDetails
|
|||||||
return $aAddress;
|
return $aAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addGeocodeJsonAddressParts(&$aJson)
|
||||||
|
{
|
||||||
|
$aFieldMappings = array(
|
||||||
|
'house_number' => 'housenumber',
|
||||||
|
'road' => 'street',
|
||||||
|
'locality' => 'locality',
|
||||||
|
'postcode' => 'postcode',
|
||||||
|
'city' => 'city',
|
||||||
|
'district' => 'district',
|
||||||
|
'county' => 'county',
|
||||||
|
'state' => 'state',
|
||||||
|
'country' => 'country'
|
||||||
|
);
|
||||||
|
|
||||||
|
$aAddrNames = $this->getAddressNames();
|
||||||
|
foreach ($aFieldMappings as $sFrom => $sTo) {
|
||||||
|
if (isset($aAddrNames[$sFrom])) {
|
||||||
|
$aJson[$sTo] = $aAddrNames[$sFrom];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getAdminLevels()
|
public function getAdminLevels()
|
||||||
{
|
{
|
||||||
$aAddress = array();
|
$aAddress = array();
|
||||||
|
|||||||
@@ -33,24 +33,9 @@ if (empty($aPlace)) {
|
|||||||
$aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
|
$aFilteredPlaces['properties']['geocoding']['name'] = $aPlace['placename'];
|
||||||
|
|
||||||
if (isset($aPlace['address'])) {
|
if (isset($aPlace['address'])) {
|
||||||
$aFieldMappings = array(
|
$aPlace['address']->addGeocodeJsonAddressParts(
|
||||||
'house_number' => 'housenumber',
|
$aFilteredPlaces['properties']['geocoding']
|
||||||
'road' => 'street',
|
);
|
||||||
'locality' => 'locality',
|
|
||||||
'postcode' => 'postcode',
|
|
||||||
'city' => 'city',
|
|
||||||
'district' => 'district',
|
|
||||||
'county' => 'county',
|
|
||||||
'state' => 'state',
|
|
||||||
'country' => 'country'
|
|
||||||
);
|
|
||||||
|
|
||||||
$aAddressNames = $aPlace['address']->getAddressNames();
|
|
||||||
foreach ($aFieldMappings as $sFrom => $sTo) {
|
|
||||||
if (isset($aAddressNames[$sFrom])) {
|
|
||||||
$aFilteredPlaces['properties']['geocoding'][$sTo] = $aAddressNames[$sFrom];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$aFilteredPlaces['properties']['geocoding']['admin']
|
$aFilteredPlaces['properties']['geocoding']['admin']
|
||||||
= $aPlace['address']->getAdminLevels();
|
= $aPlace['address']->getAdminLevels();
|
||||||
|
|||||||
@@ -23,24 +23,9 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
|
|||||||
$aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
|
$aPlace['properties']['geocoding']['name'] = $aPointDetails['placename'];
|
||||||
|
|
||||||
if (isset($aPointDetails['address'])) {
|
if (isset($aPointDetails['address'])) {
|
||||||
$aFieldMappings = array(
|
$aPointDetails['address']->addGeocodeJsonAddressParts(
|
||||||
'house_number' => 'housenumber',
|
$aPlace['properties']['geocoding']
|
||||||
'road' => 'street',
|
);
|
||||||
'locality' => 'locality',
|
|
||||||
'postcode' => 'postcode',
|
|
||||||
'city' => 'city',
|
|
||||||
'district' => 'district',
|
|
||||||
'county' => 'county',
|
|
||||||
'state' => 'state',
|
|
||||||
'country' => 'country'
|
|
||||||
);
|
|
||||||
|
|
||||||
$aAddrNames = $aPointDetails['address']->getAddressNames();
|
|
||||||
foreach ($aFieldMappings as $sFrom => $sTo) {
|
|
||||||
if (isset($aAddrNames[$sFrom])) {
|
|
||||||
$aPlace['properties']['geocoding'][$sTo] = $aAddrNames[$sFrom];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$aPlace['properties']['geocoding']['admin']
|
$aPlace['properties']['geocoding']['admin']
|
||||||
= $aPointDetails['address']->getAdminLevels();
|
= $aPointDetails['address']->getAdminLevels();
|
||||||
|
|||||||
Reference in New Issue
Block a user