You are here

public function GeofieldProximitySourceBase::getHaversineOptions in Geofield 8

Gets the haversine options.

Return value

array The haversine options.

Throws

\Drupal\geofield\Exception\HaversineUnavailableException; If the haversine is unavailable, due to incorrect setup definitions.

Overrides GeofieldProximitySourceInterface::getHaversineOptions

File

src/Plugin/GeofieldProximitySourceBase.php, line 172

Class

GeofieldProximitySourceBase
Base class for Geofield Proximity Source plugins.

Namespace

Drupal\geofield\Plugin

Code

public function getHaversineOptions() {
  $origin = $this
    ->getOrigin();
  if (!$origin || !isset($origin['lat']) || !isset($origin['lon'])) {
    throw new HaversineUnavailableException('Not able to calculate Haversine Options due to invalid Proximity Origin definition.');
  }
  if ($this
    ->isEmptyLocation($origin['lat'], $origin['lon']) || !$this
    ->isValidLocation($origin['lat'], $origin['lon'])) {
    return NULL;
  }
  return [
    'origin_latitude' => $origin['lat'],
    'origin_longitude' => $origin['lon'],
    'earth_radius' => constant($this->units),
  ];
}