Calculation based database filter

Hello,

I need to filter items in the database depending on a calculated distance.

Lets say i have a bunch of items in the data base that include their latitude and longitude as two of the database fields.

I want to show which database rows items are within a certain distance from my location.

So i have to make a filter that takes my coordinates, and each of the database items coordinates, then calculate the distance, then show which ones are within 1 mile of my location.

anyone know how i would do make a filter like this?

I know how to calculate the distance,

function distance (lat1,lon1,lat2,lon2)
{
result =calc_dist(lat1,lon1,lat2,lon2); // assume this function exists
return result;
}

All i have now is this below from a wix example

function filter(title) {
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘title’,title));
}

But how to i add the distance calculation into the filter?

Thanks

Hi!

Check those past posts that might help you achieve your goal:

And this article regarding setting a filter:

Hope it helps!
Best of luck.

Doron. :slight_smile: