Published:
5 January 2010
Concepts Discussed:
Data Source Filters, Field Types, Fields, and Pages

Step 4. Select Entries with a Data Source

A “find my nearest” application works by starting at a known location (the origin) such as your postcode. It then finds all locations within a given radius of the origin. Provided you know the latitude/longitude of the origin and of the points around it, building the radius range is a tricky mathematical calculation. To account for the curvature of the Earth’s surface we use the Haversine formula which is accurate to several metres over several hundred miles. More than enough for our needs. Thankfully, the Map Location Field does these calculations for you. All you need to know is the syntax for a Data Source filter.

In the backend navigate to Blueprints > Data Sources and click the Create New button. Name the Data Source Stores By Location and be sure it is querying the Stores section we just created.

Then add a new Filter by selecting our Location field from the dropdown and clicking the Add item button. The Map Location Field README file describes the filter in more detail, but put simply a filter should look like this:

within 50 miles of Manchester, UK

Or more specifically:

within `range` `unit` of `origin`

For the purpose of our store locator we are going to give users the option of choosing the range and origin. We’ll fix the units (km or miles) to a preference that suits your audience. The eventual store locator page will be called on a URL like this:

/store-locator/?range=50&postcode=WD3+1HH

To get these values into the data source filter we can use the querystring parameter syntax:

within {$url-range} km of {$url-postcode}

Leave the default sorting options (we’ll be sorting the entries in the XSLT) and increase the limit to something like 100 — we want to give our users choice. Then include the name, address and location items from the Included Elements list at the bottom.

Click the Create Data Source button, and you are left with a data source primed for radius searching action.

Step 5. Displaying Entries on a Page →

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details