You are here

public function GoogleCountryFormattingBase::format in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/src/GoogleCountryFormattingBase.php \Drupal\geolocation_google_maps\GoogleCountryFormattingBase::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

6 calls to GoogleCountryFormattingBase::format()
Austria::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Austria.php
Reverse geocode an address.
Belgium::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Belgium.php
Reverse geocode an address.
Germany::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Germany.php
Reverse geocode an address.
Italy::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Italy.php
Reverse geocode an address.
Spain::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Spain.php
Reverse geocode an address.

... See full list

6 methods override GoogleCountryFormattingBase::format()
Austria::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Austria.php
Reverse geocode an address.
Belgium::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Belgium.php
Reverse geocode an address.
Germany::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Germany.php
Reverse geocode an address.
Italy::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Italy.php
Reverse geocode an address.
Spain::format in modules/geolocation_google_maps/src/Plugin/geolocation/GeocoderCountryFormatting/Spain.php
Reverse geocode an address.

... See full list

File

modules/geolocation_google_maps/src/GoogleCountryFormattingBase.php, line 16

Class

GoogleCountryFormattingBase
Defines an interface for geolocation google geocoder country plugins.

Namespace

Drupal\geolocation_google_maps

Code

public function format(array $atomics) {
  $address_elements = parent::format($atomics);
  if (isset($atomics['streetNumber']) && isset($atomics['route']) && $atomics['streetNumber'] && $atomics['route']) {
    $address_elements['addressLine1'] = $atomics['streetNumber'] . ' ' . $atomics['route'];
  }
  elseif (isset($atomics['route']) && $atomics['route']) {
    $address_elements['addressLine1'] = $atomics['route'];
  }
  elseif (isset($atomics['premise']) && $atomics['premise']) {
    $address_elements['addressLine1'] = $atomics['premise'];
  }
  if (isset($atomics['locality']) && isset($atomics['postalTown']) && $atomics['locality'] && $atomics['postalTown'] && $atomics['locality'] !== $atomics['postalTown']) {
    $address_elements['addressLine2'] = $atomics['locality'];
  }
  elseif (empty($atomics['locality']) && isset($atomics['neighborhood']) && $atomics['neighborhood']) {
    $address_elements['addressLine2'] = $atomics['neighborhood'];
  }
  if (isset($atomics['locality']) && $atomics['locality']) {
    $address_elements['locality'] = $atomics['locality'];
  }
  elseif (isset($atomics['postalTown']) && $atomics['postalTown']) {
    $address_elements['locality'] = $atomics['postalTown'];
  }
  elseif (empty($atomics['locality']) && isset($atomics['political']) && $atomics['political']) {
    $address_elements['locality'] = $atomics['political'];
  }
  if (isset($atomics['postalCode']) && $atomics['postalCode']) {
    $address_elements['postalCode'] = $atomics['postalCode'];
  }
  if (isset($atomics['postalCode']) && $atomics['postalCode']) {
    $address_elements['postalCode'] = $atomics['postalCode'];
  }
  if (isset($atomics['administrativeArea']) && $atomics['administrativeArea']) {
    $address_elements['administrativeArea'] = $atomics['administrativeArea'];
  }
  if (isset($atomics['countryCode']) && $atomics['countryCode']) {
    $address_elements['countryCode'] = $atomics['countryCode'];
  }
  return $address_elements;
}