_latitude = $_GET['latitude']; $this->_longitude = $_GET['longitude']; } /** * provide a default option for the distance radius look up */ function option_definition() { $options = parent::option_definition(); // default radius $options['radius'] = array('default' => 10); // make the operator optional $options['operator']['default'] = 'optional'; $options['exposed']['default'] = TRUE; return $options; } /** * present the expose options */ function expose_options() { parent::expose_options(); $this->options['expose']['identifier'] = 'location'; } /** * provides an admin form for the options */ function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['radius'] = array( '#type' => 'select', '#title' => t('Search Radius'), '#default_value' => $this->options['radius'], '#options' => drupal_map_assoc(range(10, 100, 10)), '#description' => t('In miles'), ); } /** * Provide a simple textfield for equality */ function exposed_form(&$form, &$form_state) { if (isset($this->options['expose']['identifier'])) { $key = $this->options['expose']['identifier']; $form[$key] = array( '#type' => 'textfield', '#size' => 15, '#default_value' => $this->value, '#attributes' => array('title' => t('Enter the terms you wish to search for.')), ); $form['latitude'] = array( '#type' => 'hidden', '#value' => 0, ); $form['longitude'] = array( '#type' => 'hidden', '#value' => 0, ); $form['country'] = array( '#type' => 'hidden', '#value' => 'us', ); // add teh JS $gkey = gmap_get_key(); $script = 'document.write(unescape("%3Cscript type=\"text/javascript\" src=\"http://maps.google.com/maps?file=api&v=2.x&key=' . $gkey . ' \"%3E%3C/script%3E"));'; drupal_add_js($script, 'inline', 'footer'); drupal_add_js(' Drupal.behaviors.locationViewsGeocode = function() { var $location = $("#edit-' . $key . '"); var $country = $("#edit-country"); var $submit = $(".views-exposed-widget input:submit"); // add in a click function to prevent form from submiting $submit.click(function() { return false; // prevent it from submitting now }); // heres the real submit function ;) $submit.click(function () { if ($location.val() == "") { $(".view-filters > form").submit(); return; // we done here } var geocoder = new GClientGeocoder(); // now we geocode via Google. YA! geocoder.getLocations($location.val() + "," + $country.val() , function(response) { // if valid geocode if (response.Status.code == 200) { // clear the old error if shown if ($("#error-location").length) { $("#error-location").remove(); $location.removeClass("error"); } place = response.Placemark[0]; $("#edit-latitude").val(place.Point.coordinates[1]); $("#edit-longitude").val(place.Point.coordinates[0]); $(".view-filters > form").submit(); } else { if (!$("#error-location").length) { $location.addClass("error"); $location.parent().prepend(\'
\'); $("#edit-state").val(""); $("#edit-city").val(""); $("#edit-latitude").val(""); $("#edit-longitude").val(""); } } }); }); }; ', 'inline'); } } /** * tell apachesolr howto query with this */ function query() { if (!empty($this->_latitude)) { // do my stuff here $this->query->set_param('lat', $this->_latitude); $this->query->set_param('long', $this->_longitude); $this->query->set_param('radius', $this->options['radius']); $this->query->change_query_template('geo'); // add the params to the url for the facet blocks $this->query->add_url_query_param('latitude', $this->_latitude); $this->query->add_url_query_param('longitude', $this->_longitude); } } }