Drupal Association members fund grants that make connections all over the world.
The Goal: Five minutes to location based search results
This page will describe how to create a basic Dealer Locator, User Locator, Store Locator, etc with proximity search. The results will be displayed using Views. Your users will be able to search using friendly strings, such as "City, State", "State", "Province", and "Post/Zipcode" and return a result list ordered by proximity/distance.
The result will not show a map, only a simple list of results ordered by proximity.
There is a lot of documentation in the Drupal geolocation community that is focused on creating maps, which can make anyone new to the Drupal geocoding modules confused about where to begin for simple requirements. Fear not, the steps are actually very easy to accomplish, and you will have a 'store locator' running in minutes.
You must download the latest modules. These instructions have been tested with the 'dev' versions of geocoder, geofield, and addressfield modules. I believe these modules have a dependency on geophp, maybe others, install any dependent modules that you are instructed to when installing. Make sure to download the 'dev' versions!
Setup your content type
- Create a content type for whatever you want to locate (e.g. Dealers, Stores, etc)
- In manage fields: Add an addressfield field to the content type (use options as you see fit).
- In manage fields: Add a geofield field to the content type. When adding, make sure to select 'Geocode from another field' from the 'widget' dropdown! The geofield option are pretty straightforward, just make sure to select the addressfield field you created earlier for the 'Geocode from field' option.
- Now, create a few records with addresses using your new content type.
That was easy! Now, let's setup the view result...
Setup your views query
- Create a view, can be any kind. Select the content type you created earlier for the results.
- Add a field: '[name of your geofield] - proximity' (there are a number of geocoding related fields, you want the one with '- proximity' appended)
- In the field settings: For the 'Source of Origin Point' field, select 'Exposed Geofield Proximity Filter'.
- Add any other identifying fields, such as title, address, etc.
- Add a new 'Filter Criteria' for your view for the '[name of your geofield] - proximity' field.
- Choose 'Expose this filter to visitors, to allow them to change it'
- For 'Operator', choose 'Is less than', because you want results that are closer than a certain distance from the value your users enters, e.g. less than 100 kilometers, etc.
- For 'Source of Origin Point', choose 'Geocoded Location', which will allow the user enter friendly values such as city, state, zip/postecode, state, etc. (basically, anything you can put into Google location searches).
- For Geocoding Service, choose 'Google Geocoder'.
- Add a Sort Criteria: '[name of your geofield] - proximity'. Also, remove any other sort filter already existing, since sorting by date first will foil your proximity filter!
- Set to sort ascending, since you probably want to show the closest results first.
- Set 'Source of Origin Point' to 'Exposed Geofield Proximity Filter'.
- Test your new proximity search!
Wow, not bad! I remember coding a dealer locator like this by hand. Ouch. Took a lot longer than five minutes!
Credit: These steps are copied generally from http://drupal.stackexchange.com/questions/54873/geofield-proximity-in-views