Basic Dealer Locator, User Locator, Store Locator proximity search

Last updated on
30 April 2025

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.

Background

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.

Instructions

Required modules

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!

Steps

Setup your content type

  1. Create a content type for whatever you want to locate (e.g. Dealers, Stores, etc)
  2. In manage fields: Add an addressfield field to the content type (use options as you see fit).
  3. 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.
  4. 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

  1. Create a view, can be any kind. Select the content type you created earlier for the results.
  2. Add a field: '[name of your geofield] - proximity' (there are a number of geocoding related fields, you want the one with '- proximity' appended)
  3. In the field settings: For the 'Source of Origin Point' field, select 'Exposed Geofield Proximity Filter'.
  4. Add any other identifying fields, such as title, address, etc.
  5. Add a new 'Filter Criteria' for your view for the '[name of your geofield] - proximity' field.
  6. Choose 'Expose this filter to visitors, to allow them to change it'
  7. 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.
  8. 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).
  9. For Geocoding Service, choose 'Google Geocoder'.
  10. 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!
  11. Set to sort ascending, since you probably want to show the closest results first.
  12. Set 'Source of Origin Point' to 'Exposed Geofield Proximity Filter'.
  13. 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

Help improve this page

Page status: Not set

You can: