You are here

public function SearchApiViewsHandlerFieldLocation::render in Search API Location 7.2

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides entity_views_handler_field_text::render

File

search_api_location_views/handler_field_location.inc, line 173
Contains SearchApiViewsHandlerFieldLocation.

Class

SearchApiViewsHandlerFieldLocation
Specialized handler for latitude/longitude fields.

Code

public function render($values) {

  // Render normally.
  if (empty($this->options['show_distance_to_point'])) {
    return parent::render($values);
  }

  // Render as distance.
  $value = $this
    ->get_value($values);
  if (is_numeric($value)) {
    if (!empty($this->options['set_precision'])) {
      $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
    }
    else {
      $remainder = abs($value) - intval(abs($value));
      $value = $value > 0 ? floor($value) : ceil($value);
      $value = number_format($value, 0, '', $this->options['separator']);
      if ($remainder) {
        $value .= $this->options['decimal'] . substr($remainder, 2);
      }
    }
    return $this
      ->sanitize_value($value);
  }
  return '';
}