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 diff -u -p -r1.3 location_views_handler_filter_proximity.inc --- handlers/location_views_handler_filter_proximity.inc 3 Dec 2008 22:51:23 -0000 1.3 +++ handlers/location_views_handler_filter_proximity.inc 16 Mar 2009 20:39:12 -0000 @@ -2,8 +2,8 @@ // $Id: location_views_handler_filter_proximity.inc,v 1.3 2008/12/03 22:51:23 bdragon Exp $ /** - * General proximity filter for location latitude/longitude. - */ +* General proximity filter for location latitude/longitude. +*/ class location_views_handler_filter_proximity extends views_handler_filter { // This is always single, because of the distance field's possible dependency // on it. @@ -132,7 +132,7 @@ class location_views_handler_filter_prox ); } - function exposed_form(&$form, &$form_state) { +function exposed_form(&$form, &$form_state) { parent::exposed_form($form, $form_state); $key = $this->options['expose']['identifier']; $type = $this->options['type']; @@ -152,7 +152,7 @@ class location_views_handler_filter_prox } // Used from the distance field. - function calculate_coords() { +function calculate_coords() { if (!empty($this->value['latitude']) && !empty($this->value['longitude'])) { // If there are already coordinates, there's no work for us. return TRUE; @@ -167,7 +167,14 @@ class location_views_handler_filter_prox // Zip code lookup. if (!empty($this->value['postal_code']) && !empty($this->value['country'])) { - $coord = location_latlon_rough($this->value); + $location = array('country'=> $this->value['country'], 'postal_code' => $this->value['postal_code']); + $res = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE"." zip = '%s' AND country = '%s'", $location['postal_code'], $location['country']); + if ($r = db_fetch_array($res)) { + $this->value['latitude'] = $r['latitude']; + $this->value['longitude'] = $r['longitude']; + } + $coord = location_latlon_rough($location); + if ($coord) { $this->value['latitude'] = $coord['lat']; $this->value['longitude'] = $coord['lon']; @@ -184,16 +191,18 @@ class location_views_handler_filter_prox if (empty($this->value['latitude']) || empty($this->value['longitude'])) { return false; } - return true; + return TRUE; } - - function query() { + +function query() { + $this->value['country'] = variable_get('location_default_country', 'us'); + if (empty($this->value)) { return; } - // Coordinates available? - if (!$this->calculate_coords()) { + //DG this is always empty + /*if (!$this->calculate_coords()) { // Distance set? if (!empty($this->value['search_distance'])) { // Hmm, distance set but unable to resolve coordinates. @@ -201,18 +210,30 @@ class location_views_handler_filter_prox $this->query->add_where($this->options['group'], "0"); } return; + }*/ + if (empty($this->value['postal_code'])) { + return; + } + if (!empty($this->value['postal_code'])) { + $res = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE"." zip = '%s' AND country = '%s'", $this->value['postal_code'], $this->value['country']); + if ($r = db_fetch_array($res)) { + $this->value['latitude'] = $r['latitude']; + $this->value['longitude'] = $r['longitude']; + } + } + if (empty($this->value['search_distance'])) { + $this->value['search_distance'] = 1; } - $this->ensure_my_table(); $lat = $this->value['latitude']; $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); - + // 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]); @@ -220,5 +241,8 @@ class location_views_handler_filter_prox // Add radius check. $this->query->add_where($this->options['group'], earth_distance_sql($lon, $lat, $this->table_alias) .' < %f', $distance_meters); } + //print_r($this->query); } + } +?> \ No newline at end of file