2

I tend to do a lot of roster pages on Drupal + CiviCRM sites (Drupal Views, exposing CiviCRM contact record fields). One of the search filters I'd like to try would be to allow visitors to enter a postal/zip code and then have results from contacts that are located in a radius to the postal code. I know CiviCRM has some ability to geocode contact addresses. Is there any way we can harness the goecoding into a postal/zip filter for this type of search?

  • When using Lat Long in Views we have used OpenLayers module to generate maps. Had no luck with proximity search at the time but things might have progressed though a quick look at status of drupal.org/project/openlayers_proximity suggests that may not be the solution (yet) – petednz - fuzion Jun 20 '15 at 0:26
2

I have recently updated the module to allow a map and use your location. More info can be found here - https://civicrm.org/blog/anil/drupal-views-civicrm-contact-distance-search-with-a-map

1

You would need to do some custom work to get this exposed to a public page I suspect, but CiviCRM already provides radius search, based on Zip Code.

First you need to turn on geocoding which will go get the latitude/longitudes for all the contacts you have (based on their zip code). Go here to set up: civicrm/admin/setting/mapping (note you have to allow civi the time to fully geocode your contacts as well.)

Then in Advanced Search, you can search a zip code, and say you would like to search a specific radius around that zip. (Note if geocoding is not turned on, the option to specify a radius is not displayed.)

Using Drupal Views, assuming you are geocoding,you may be able to create a view based on a radius using that stored lat/long (though that may be prohibitive CPU wise). Depends on how many contacts you need to filter. (Probably need to use a PHP filter in the view to calc the distance on each contact to determine inclusion.)

(Google for the algorithm to calc distances on lat/long)

1

As luck would have it, I was over at the Drupal project review queue and found exactly what I was looking for. It's currently on its path to being approved (hopefully soon) and currently it only supports UK postal codes but this is what I expect will be the answer (it's a sandbox project at this time):

CiviCRM contact distance search https://www.drupal.org/sandbox/vakeesan26/2498395

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.