Loading

Sorting by Distance

A browse view can offer Nearest First alongside its other sort options. The visitor supplies a starting point and the catalogue reorders around them.

Where to find it

Architect Panel → Layout & Pages:

  • Browse Views — the builder, and its Location & Distance settings

Architect Panel → Integration & Connections:

  • Postcode Lookup — the geocoding this depends on

Architect Panel → Configuration:

  • Site Settings — Look postcodes up — the master switch

Two things must be true

  1. Postcode lookup is enabled for the installation.
  2. The view has a location field configured.

Without the first, the option does not work; without the second, it is not offered. Both are deliberate — a browse view with no location configured does not load any of this machinery at all.

Where the record's location comes from

Point the view at a field that can hold one. Four kinds qualify, and the view works out what to do from the field's own type rather than asking you to declare it:

  • A text field holding a postcode.
  • A Postal Address field — the postcode is read out of it.
  • A Geolocation field — this already holds coordinates, so it needs no lookup and no cache entry at all.
  • A field on a parent record, reached through a link field on this table.

The parent-table case is the useful one

Catalogues frequently hold the thing and not the place: courses at a venue, staff at an office, products at a branch. Rather than copying a postcode onto every record — which then has to be kept in step — point the view at the link field and the postcode on the record it leads to.

One address, one place to correct it, and every child record moves with it.

The visitor's starting point

A postcode box appears beside the sort dropdown when Nearest First is chosen, with a Use my location button. The button uses the browser's own geolocation and passes the coordinates straight through — no lookup, no cost, and no round trip to convert coordinates into a postcode and back.

The typed postcode is remembered in the browser, so a returning visitor does not retype it. Browse views are anonymous, so there is no session to keep it in.

A bad postcode is not an empty catalogue

If the starting point cannot be resolved, the view says so beside the input rather than returning nothing.

That distinction matters more than it sounds: "we could not find that postcode" and "this catalogue is empty" look identical if both produce a blank list, and the visitor draws the wrong conclusion about your service rather than about their typing.

Records that cannot be placed sort last

A record whose postcode is missing or unresolvable still appears — at the end, after everything with a distance. It is not silently dropped, which would be a worse failure for a catalogue where being listed is the point.

The view can also report how many records could not be placed, which is worth surfacing while you are getting the data right.

Show the distance on the card

Two tags are available to the item template: ##AMDATA_AMdistancetext## gives a formatted distance such as "3.4 miles", and ##AMDATA_AMdistance## gives the number alone for when you want to style the unit yourself.

Miles or kilometres

Set per view. It affects the displayed distance and the radius steps together, so the two cannot disagree.

Warm the cache first

On a large catalogue, use the builder's Warm postcode cache button before anybody uses the feature. Otherwise the first visitor triggers the geocoding, bounded by the per-request ceiling, and sees an incomplete ordering until it catches up.

Worked example

A training provider lists 600 courses held at 40 venues. The view points at the link to Venue and the postcode on the venue record, so no course carries an address. The cache is warmed from the builder — 40 postcodes, one call. A visitor enters their postcode and the courses reorder, each card showing "12.4 miles" from the distance tag.

Recommendations

  • Use the parent-table option rather than copying addresses onto child records.
  • Warm the cache before launch and after every bulk import.
  • Put the distance on the card — it is the reason the visitor sorted.
  • Check how many records cannot be placed before you go live.