You are here

function geofield_handler_field::query in Geofield 7.2

Called to add the field to a query.

Overrides views_handler_field::query

File

views/handlers/geofield_handler_field.inc, line 9
Distance field implementation.

Class

geofield_handler_field
@file Distance field implementation.

Code

function query() {
  $this
    ->ensure_my_table();
  $lat_alias = $this->table_alias . '.' . $this->definition['field_name'] . '_lat';
  $lon_alias = $this->table_alias . '.' . $this->definition['field_name'] . '_lon';
  $proximityPlugin = geofield_proximity_load_plugin($this->options['source']);
  $options = $proximityPlugin
    ->getSourceValue($this);
  if ($options != FALSE) {
    $haversine_options = array(
      'origin_latitude' => $options['latitude'],
      'origin_longitude' => $options['longitude'],
      'destination_latitude' => $lat_alias,
      'destination_longitude' => $lon_alias,
      'earth_radius' => $this->options['radius_of_earth'],
    );
    $this->field_alias = $this->query
      ->add_field(NULL, geofield_haversine($haversine_options), $this->table_alias . '_' . $this->field);
  }
}