We had a list of clinics and needed to way to filter the results for a user of locations closest to them (based on a miles drop down list) and based on the zip code or their determined location.
Coveo uses query functions to help you accomplish this. All you need, in the dataset, is the latitude & longitude values and these two functions (sent by the browser to the Coveo api):
$qf(function:'dist(@latitude, @longitude, $context.lat, $context.lng)', fieldName: 'distance')Coveo computes in metric so we need to use this factor to convert the distance to miles:
$qf(function:'@distance*0.000621371', fieldName: 'distanceinmiles')I had this little extra from my notes – can’t recall why though:
@distanceinmiles<$context.range>