You are here

public function Geocoder::getCoordinates in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/geolocation/LocationInput/Geocoder.php \Drupal\geolocation\Plugin\geolocation\LocationInput\Geocoder::getCoordinates()

Get center value.

Parameters

mixed $form_value: Form value.

int $center_option_id: LocationInput option ID.

array $center_option_settings: The current feature settings.

mixed $context: Context like field formatter, field widget or view.

Return value

array Render array.

Overrides LocationInputBase::getCoordinates

File

src/Plugin/geolocation/LocationInput/Geocoder.php, line 154

Class

Geocoder
Location based proximity center.

Namespace

Drupal\geolocation\Plugin\geolocation\LocationInput

Code

public function getCoordinates($form_value, $option_id, array $option_settings, $context = NULL) {
  $coordinates = parent::getCoordinates($form_value, $option_id, $option_settings, $context);
  if ($coordinates) {
    return $coordinates;
  }
  if (empty($form_value['geocoder'])) {
    return [];
  }
  $settings = $this
    ->getSettings($option_settings);
  $location_data = $this->geocoderManager
    ->getGeocoder($settings['plugin_id'], $settings['settings'])
    ->geocode($form_value['geocoder']['geolocation_geocoder_address']);
  if (!empty($location_data['location'])) {
    return $location_data['location'];
  }
  return FALSE;
}