You are here

public function NominatimCountryFormattingBase::format in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_leaflet/src/NominatimCountryFormattingBase.php \Drupal\geolocation_leaflet\NominatimCountryFormattingBase::format()

Reverse geocode an address.

Intended return subject to available data:

[
  'organization',
  'address_line1',
  'address_line2',
  'postal_code',
  'sorting_code',
  'dependent_locality',
  'dependent_locality_code',
  'locality',
  'locality_code',
  'administrative_area',
  'administrative_area_code',
  'country',
  'country_code',
  'formatted_address',
];

Parameters

array $atomics: Address components.

Return value

array||null Address or NULL.

Overrides GeocoderCountryFormattingBase::format

1 call to NominatimCountryFormattingBase::format()
NominatimRoadFirstFormattingBase::format in modules/geolocation_leaflet/src/NominatimRoadFirstFormattingBase.php
Reverse geocode an address.
1 method overrides NominatimCountryFormattingBase::format()
NominatimRoadFirstFormattingBase::format in modules/geolocation_leaflet/src/NominatimRoadFirstFormattingBase.php
Reverse geocode an address.

File

modules/geolocation_leaflet/src/NominatimCountryFormattingBase.php, line 16

Class

NominatimCountryFormattingBase
Base class for nominatim geocoder country formatting plugins.

Namespace

Drupal\geolocation_leaflet

Code

public function format(array $atomics) {
  $address_elements = parent::format($atomics);
  if (isset($atomics['houseNumber']) && isset($atomics['road'])) {
    $address_elements['addressLine1'] = $atomics['houseNumber'] . ' ' . $atomics['road'];
  }
  elseif (isset($atomics['road'])) {
    $address_elements['addressLine1'] = $atomics['road'];
  }
  if (isset($atomics['city']) && isset($atomics['village']) && $atomics['city'] !== $atomics['village']) {
    $address_elements['addressLine2'] = $atomics['village'];
  }
  elseif (isset($atomics['suburb'])) {
    $address_elements['addressLine2'] = $atomics['suburb'];
  }
  if (isset($atomics['city'])) {
    $address_elements['locality'] = $atomics['city'];
  }
  elseif (empty($atomics['city']) && isset($atomics['county'])) {
    $address_elements['locality'] = $atomics['county'];
  }
  if (isset($atomics['postcode'])) {
    $address_elements['postalCode'] = $atomics['postcode'];
  }
  if (isset($atomics['countryCode'])) {
    $address_elements['countryCode'] = $atomics['countryCode'];
  }
  return $address_elements;
}