Sorting by Distance
A browse view can offer Nearest First in its Sort By list. The visitor types a postcode or shares their location, and the listing reorders around them, with each record's distance available to show on its card.
Where to find it
Architect Panel → Layout & Pages:
- Browse Views — open a view in the Browse View Builder and use its Location & Distance card
Architect Panel → Integration & Connections:
- Postcode Lookup — the postcode positions distances are worked out from
Where a record's location comes from
In the Location & Distance card, Postcode Field lists every field that can hold a location, grouped under "On this datastore" and "Linked through" a dropdown field. Three kinds qualify:
- A text field holding a postcode. Its position comes from postcode lookup.
- A Postal Address field. If the address was captured with address autocomplete, its saved coordinates are used; otherwise its postcode is looked up.
- A Geolocation field storing coordinates, used directly with no lookup. One configured to store an address is marked with a warning.
"Linked through" reads the location from the record a Dropdown (DB) or searchable dropdown points at, such as a placement's employer site. Only one hop is supported.
Setting it up
- Open the view in the Browse View Builder and find Location & Distance.
- Choose the Postcode Field.
- Tick Offer Nearest First. Without it, nothing else in the card takes effect.
- Tick Show Distances In Km for kilometres; leave it unticked for miles.
- Click Save Browse Layout.
- If the field holds postcodes, click Warm postcode cache (under Postcode Cache) and repeat until it reports the cache is complete for this view. Save first.
- Add
##AMDATA_AMdistancetext##to the List template under Item Appearances to show the distance on each card. The distance tags appear in the Placeholder Tags panel once Offer Nearest First is on.
What the visitor sees
- They choose Nearest First in Sort By. A row labelled Your postcode appears, with a Use my location button.
- They type a postcode or use their location. The view reorders and shows "Showing distances from" the postcode or "Your location".
- A postcode that resolved is remembered in their browser for next time.
Distances are straight-line, rounded to one decimal place. Records with no position are still listed, at the end, with no distance. Until the visitor gives a starting point, Nearest First leaves the order unchanged.
What goes wrong and how to tell
- "We could not find that postcode. Please check it and try again.": the visitor's postcode is not known. If postcode lookup is switched off, only postcodes already in the cache are recognised.
- "We could not get your location. Please type your postcode instead.": the browser refused or failed to share a location.
- Many records sort last: their postcodes are not cached yet, could not be found, or contain stray punctuation. Warm the cache and check the not-found list on Postcode Lookup.
- "This view has no postcode field configured yet. Choose one and save first." when warming: save the card with Offer Nearest First ticked.
- "This view reads coordinates straight from a Geolocation field, so there is nothing to look up.": no warming is needed.
Worked example
A work-experience catalogue lists placements, each linked to an employer site holding a postcode. The architect sets Postcode Field to the site's postcode, linked through the placement's Site dropdown, ticks Offer Nearest First, saves, and warms the cache in two runs. They add "##AMDATA_AMdistancetext## away" to the List template. A student types their postcode, picks Nearest First, and sees "2.4 miles away" on the closest placement.
Recommendations
- Prefer coordinates where you have them: they need no lookup.
- Warm the cache before launch.
- Show the distance on the card, so the order makes sense to visitors.
- Say the distances are straight-line in the view's introduction.