Index: location.views.inc
===================================================================
--- location.views.inc (revision 5021)
+++ location.views.inc (working copy)
@@ -51,6 +51,9 @@
'location_handler_argument_location_province' => array(
'parent' => 'views_handler_argument',
),
+ 'location_handler_argument_location_proximity' => array(
+ 'parent' => 'views_handler_argument',
+ ),
'location_handler_field_location_address' => array(
'parent' => 'views_handler_field',
),
@@ -306,6 +309,9 @@
'filter' => array(
'handler' => 'location_views_handler_filter_proximity',
),
+ 'argument' => array(
+ 'handler' => 'location_handler_argument_location_proximity',
+ ),
// 'relationship' => array(
// 'handler' => 'location_handler_relationship_location_distance',
// ),
Index: handlers/location_handler_argument_location_proximity.inc
===================================================================
--- handlers/location_handler_argument_location_proximity.inc (revision 0)
+++ handlers/location_handler_argument_location_proximity.inc (revision 0)
@@ -0,0 +1,111 @@
+ 'select',
+ '#title' => t('Proximity type'),
+ '#weight' => -47,
+ '#description' => t('Square (faster) or circle (more accurate)?'),
+ '#default_value' => $this->options['operator'],
+ '#options' => array('mbr' => t('Square'),'dist' => t('Circular'))
+ );
+
+ $form['help'] = array(
+ '#type' => 'item',
+ '#weight' => -50,
+ '#title' => t('Parameter usage'),
+ '#description' => t('This parameter accepts 3 values separated by semicolon:
lat;lon[;dist]
lat - latitude float number
lon - longitude float number
dist - distance in selected units integer (optional, defaults to setting below)
example usages:
12.345;23.456
12.345;23.456;100'),
+ );
+
+ //units used
+ $form['search_units'] = array(
+ '#type' => 'select',
+ '#title' => t('Distance unit'),
+ '#weight' => -49,
+ '#options' => array(
+ 'km' => t('Kilometers'),
+ 'm' => t('Meters'),
+ 'mile' => t('Miles'),
+ ),
+ '#default_value' => $this->options['search_units'],
+ );
+
+ //default 3rd parameter
+ $form['default_distance'] = array(
+ '#weight' => -48,
+ '#type' => 'textfield',
+ '#title' => t('Default Distance'),
+ '#default_value' => $this->options['default_distance'],
+ '#description' => t('When 3rd number is ommitted'),
+ );
+
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+ $options['operator'] = array('default' => 'dist');
+ $options['search_units'] = array('default' => 'm');
+ $options['default_distance'] = array('default' => '100');
+ return $options;
+ }
+
+ function admin_summary() {
+ return '';
+ }
+
+ //splitting argument to 3 vals
+ function break_arg($arg) {
+ $argv = explode(';',$arg);
+ $argc = count($argv);
+ if ($argc==3) {
+ //distnce is int - see _location_convert_distance_to_meters() why
+ return array(floatval($argv[0]),floatval($argv[1]),intval($argv[2]));
+ }
+ if ($argc==2) {
+ return array(floatval($argv[0]),floatval($argv[1]),intval($this->options['default_distance']));
+ }
+ return false;
+ }
+
+
+ function query() {
+ if (!$this->coords = $this->break_arg($this->argument)) return;
+ $this->ensure_my_table();
+
+ $lat = $this->coords[0];
+ $lon = $this->coords[1];
+ $distance = $this->coords[2];
+ if ($this->options['search_units'] =='m')
+ $distance_meters = $distance;
+ else
+ $distance_meters = _location_convert_distance_to_meters($distance, $this->options['search_units']);
+
+ $latrange = earth_latitude_range($lon, $lat, $distance_meters);
+ $lonrange = earth_longitude_range($lon, $lat, $distance_meters);
+
+ // Add MBR check (always.)
+ $this->query->add_where($this->options['group'], "$this->table_alias.latitude > %f AND $this->table_alias.latitude < %f AND $this->table_alias.longitude > %f AND $this->table_alias.longitude < %f", $latrange[0], $latrange[1], $lonrange[0], $lonrange[1]);
+
+ if ($this->operator == 'dist') {
+ // Add radius check.
+ $this->query->add_where($this->options['group'], earth_distance_sql($lon, $lat, $this->table_alias) .' < %f', $distance_meters);
+ }
+
+ }
+
+}