Index: location.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/location.inc,v
retrieving revision 1.95.2.4
diff -u -F '^f' -r1.95.2.4 location.inc
--- location.inc	19 Jan 2010 02:02:03 -0000	1.95.2.4
+++ location.inc	19 Feb 2010 01:28:46 -0000
@@ -225,14 +225,7 @@ function _location_convert_distance_to_m
     return NULL;
   }
 
-  // Force an integer version of distance, just in case anyone wants to add a caching mechanism
-  // for postal code proximity searches.
-
-  if (is_float($distance)) {
-    $distance = intval(ceil($distance));
-  }
-
-  if ($distance < 1) {
+  if ($distance == 0) {
     return NULL;
   }
 
Index: handlers/location_handler_field_location_distance.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/handlers/location_handler_field_location_distance.inc,v
retrieving revision 1.2.2.1
diff -u -F '^f' -r1.2.2.1 location_handler_field_location_distance.inc
--- handlers/location_handler_field_location_distance.inc	21 Jan 2009 21:39:16 -0000	1.2.2.1
+++ handlers/location_handler_field_location_distance.inc	19 Feb 2010 01:28:46 -0000
@@ -40,19 +40,34 @@
         'hybrid' => t("User's location (fall back to static if unset)"),
         'static' => t("Static location"),
         'tied' => t("Use Distance / Proximity filter"),
+        'php' => t('Enter PHP code to determine latitude/longitude used to set the location from which the distance will be computed.')
       ),
       '#description' => t('FIXME'),
       '#default_value' => $this->options['origin'],
     );
+    
     $form['latitude'] = array(
       '#type' => 'textfield',
       '#title' => t('Latitude'),
       '#default_value' => $this->options['latitude'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
     $form['longitude'] = array(
       '#type' => 'textfield',
       '#title' => t('Longitude'),
       '#default_value' => $this->options['longitude'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
+    );
+    
+    $form['php_code'] = array(
+      '#type' => 'textarea',
+      '#title' => t('PHP code for latitude, longitude'),
+      '#default_value' => $this->options['php_code'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('php')),
+      '#description' => t('Enter PHP code that returns a latitude/longitude.  Do not use &lt;?php ?&gt;. You must return only an array with float values set for the \'latitude\' and \'longitude\' keys.')
     );
   }
 
@@ -104,6 +119,22 @@
         }
       }
     }
+    
+    if ($this->options['origin'] == 'php') {
+      $view = &$this->view;
+      
+      //$this_keys_exp = var_export((array) $this, TRUE);
+      //drupal_set_message("(array) \$this->keys == <pre>$this_keys_exp</pre>");
+      
+      ob_start();
+      $result = eval($this->options['php_code']);
+      ob_end_clean();
+      
+      if ($result && $result['latitude'] && $result['longitude']) {
+        $latitude = $result['latitude'];
+        $longitude = $result['longitude'];
+      }
+    }
 
     $this->ensure_my_table();
 
Index: handlers/location_handler_sort_location_distance.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/handlers/location_handler_sort_location_distance.inc,v
retrieving revision 1.1
diff -u -F '^f' -r1.1 location_handler_sort_location_distance.inc
--- handlers/location_handler_sort_location_distance.inc	3 Dec 2008 22:51:23 -0000	1.1
+++ handlers/location_handler_sort_location_distance.inc	19 Feb 2010 01:28:46 -0000
@@ -48,11 +48,15 @@
       '#type' => 'textfield',
       '#title' => t('Latitude'),
       '#default_value' => $this->options['latitude'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
     $form['longitude'] = array(
       '#type' => 'textfield',
       '#title' => t('Longitude'),
       '#default_value' => $this->options['longitude'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
   }
 
Index: handlers/location_views_handler_filter_proximity.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/location/handlers/location_views_handler_filter_proximity.inc,v
retrieving revision 1.3.2.1
diff -u -F '^f' -r1.3.2.1 location_views_handler_filter_proximity.inc
--- handlers/location_views_handler_filter_proximity.inc	22 Jan 2010 16:38:05 -0000	1.3.2.1
+++ handlers/location_views_handler_filter_proximity.inc	19 Feb 2010 01:28:46 -0000
@@ -79,7 +79,20 @@
 
   function value_form(&$form, &$form_state) {
     $val = $this->value;
-
+    
+    $form['origin'] = array(
+      '#type' => 'radios',
+      '#title' => t('Origin'),
+      '#options' => array(
+        'user' => t("User's location (blank if unset)"),
+        'hybrid' => t("User's location (fall back to static if unset)"),
+        'static' => t("Static location"),
+        'php' => t('Enter PHP code to determine latitude/longitude used to set the location from which the distance will be computed.')
+      ),
+      '#description' => t('This will be the way the latitude/longitude of origin is determined.  If this filter is exposed, this will determine the default values.'),
+      '#default_value' => $this->options['origin'] ? $this->options['origin'] : 'user'
+    );
+    
     // [11:44] <merlinofchaos> If you load the page from scratch, $input for your identifier will be empty.
     // [11:44] <merlinofchaos> So what's going on here is that for $_GET forms, there's no form id, no op button or anything, so they always appear to submit.
     // [11:45] <merlinofchaos> FAPI doesn't quite get along with that; sometimes it handles the input being empty right and sometimes it doesn't.
@@ -108,14 +121,16 @@
       '#title' => t('Latitude'),
       '#default_value' => $this->value['latitude'],
       '#process' => array('views_process_dependency'),
-      '#dependency' => array('edit-options-type' => array('latlon', 'latlon_gmap')),
+      //'#dependency' => array('edit-options-type' => array('latlon', 'latlon_gmap')),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
     $form['value']['longitude'] = array(
       '#type' => 'textfield',
       '#title' => t('Longitude'),
       '#default_value' => $this->value['longitude'],
       '#process' => array('views_process_dependency'),
-      '#dependency' => array('edit-options-type' => array('latlon', 'latlon_gmap')),
+      //'#dependency' => array('edit-options-type' => array('latlon', 'latlon_gmap')),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
 
     $form['value']['postal_code'] = array(
@@ -123,7 +138,8 @@
       '#title' => t('Postal code'),
       '#default_value' => $this->value['postal_code'],
       '#process' => array('views_process_dependency'),
-      '#dependency' => array('edit-options-type' => array('postal', 'postal_default')),
+      //'#dependency' => array('edit-options-type' => array('postal', 'postal_default')),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
     );
 
     $form['value']['country'] = array(
@@ -132,7 +148,18 @@
       '#options' => array('' => '') + location_get_iso3166_list(),
       '#default_value' => $this->value['country'],
       '#process' => array('views_process_dependency'),
-      '#dependency' => array('edit-options-type' => array('postal')),
+      //'#dependency' => array('edit-options-type' => array('postal')),
+      '#dependency' => array('radio:options[origin]' => array('hybrid', 'static'))
+    );
+    
+    $form['value']['php_code'] = array(
+      '#type' => 'textarea',
+      '#title' => t('PHP code for latitude, longitude'),
+      '#default_value' => $this->options['php_code'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[origin]' => array('php')),
+      '#description' => t('Enter PHP code that returns a latitude/longitude.  Do not use &lt;?php ?&gt;. You must return only an array with float values set for the \'latitude\' and \'longitude\' keys.'),
+      '#default_value' => $this->value['php_code']
     );
 
     $form['value']['search_distance'] = array(
@@ -177,10 +204,45 @@
     if ($type != 'postal') {
       unset($form[$key]['country']);
     }
+    
+    // And we definitely do not want to expose the php code option when exposing the filter
+    unset($form[$key]['php_code']);
+    unset($form['origin']);
   }
 
   // Used from the distance field.
   function calculate_coords() {
+    if ($this->options['origin'] == 'php') {
+      $view = $this->view;
+      
+      ob_start();
+      $result = eval($this->value['php_code']);
+      ob_end_clean();
+      
+      if ($result && $result['latitude'] && $result['longitude']) {
+        $this->value['latitude'] = $result['latitude'];
+        $this->value['longitude'] = $result['longitude'];
+        return TRUE;
+      }
+      else {
+        return FALSE;
+      }
+    }
+    
+    if ($this->options['origin'] == 'user' || $this->options['origin'] == 'hybrid') {
+      global $user;
+      if (!isset($user->locations)) {
+        $user = user_load($user->uid);
+      }
+      if (isset($user->locations[0]['latitude']) || !empty($user->locations[0]['latitude'])) {
+        $this->value['latitude'] = (float)$user->locations[0]['latitude'];
+        $this->value['longitude'] = (float)$user->locations[0]['longitude'];
+      }
+      elseif ($this->options['origin'] == 'user') {
+        return FALSE;
+      }
+    }
+    
     if (!empty($this->value['latitude']) && !empty($this->value['longitude'])) {
       // If there are already coordinates, there's no work for us.
       return TRUE;
@@ -237,7 +299,6 @@
     $lon = $this->value['longitude'];
 
     $distance_meters = _location_convert_distance_to_meters($this->value['search_distance'], $this->value['search_units']);
-
     $latrange = earth_latitude_range($lon, $lat, $distance_meters);
     $lonrange = earth_longitude_range($lon, $lat, $distance_meters);
 
