I am currently working on a custom module that will filter search results (each result being a node already containing longitude and latitude data) based on their longitude and latitude.
I've used mymodule_form_alter to add a textfield to Drupal's built-in Search form block. This extra field lets users enter an address, which will be used to filter the search results to only those within a 15-mile radius of this address.
My next step (I think) is to use mymodule_db_rewrite_sql to, after geocoding and getting the longitude and latitude of the user-inputted address, add a WHERE clause (like the one seen here: http://drupal.org/node/89220#comment-457528) to filter out any results outside the 15-mile radius.
However, I'm not sure how to access the user-inputted address, since the $form_state variable is not passed to db_rewrite_sql, and I believe this variable is needed to access form values. So I am kind of stuck at this point...any suggestions?
Comments
You could look at
You could look at implementing your own search type with hook_search (http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...) and defaulting all searches to go through that. That way you could run a completely custom query for the nodes you want to display.
Thanks for the suggestion!
Thanks for the suggestion! However, I am still slightly confused on how to access the user-inputted address within hook_search, since the $form_state variable is not passed to hook_search. I used dsm($keys), which revealed that $keys contains the search keywords but not the user-inputted address. Any thoughts on where to go from here?
Without implementing a whole
Without implementing a whole system around it the easiest way to do it would be to geocode the address and set a session var when the search form itself submits. That way in hook_search you can do this: