You are here

public function LocationDataType::getValue in Search API Location 8

Converts a field value to match the data type (if needed).

Parameters

mixed $value: The value to convert.

Return value

mixed The converted value.

Overrides DataTypePluginBase::getValue

File

src/Plugin/search_api/data_type/LocationDataType.php, line 21

Class

LocationDataType
Provides the location data type.

Namespace

Drupal\search_api_location\Plugin\search_api\data_type

Code

public function getValue($value) {
  $geom = \geoPHP::load($value);
  if ($geom) {
    $centroid = $geom
      ->getCentroid();
    $lon = $centroid
      ->getX();
    $lat = $centroid
      ->getY();
    return "{$lat},{$lon}";
  }
  else {
    return $value;
  }
}