Database - Search by Address

I have searched and it seems this topic hasn’t been covered.

I have a repeater linked to a dataset. Each item has an address (amoungst other data). I would like users to be able to search the nearest locations near them, by entering in their post code/city/town into a search bar, and the results from the database appearing below (nearest first? Within 10 miles etc?).

Is there a Velo solution to this, or a workaround?

Thanks in advance.

Generate your own DISTANCE-CALCULATOR-FUNCTION, which will calculate the distance between two Points on a map (using longitude-koordinates, and latitude-koordinates)

Someting like…

function calculateDistance(lat1, lon1, lat2, lon2) {
  const earthRadius = 6371; // in kilometers

  const toRadians = (degrees) => {
    return degrees * (Math.PI / 180);
  };

  const deltaLat = toRadians(lat2 - lat1);
  const deltaLon = toRadians(lon2 - lon1);

  const a =
    Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
    Math.cos(toRadians(lat1)) *
      Math.cos(toRadians(lat2)) *
      Math.sin(deltaLon / 2) *
      Math.sin(deltaLon / 2);

  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

  const distance = earthRadius * c;
  return distance;
}

// Example usage:
const latitude1 = 40.7128; // latitude of position 1
const longitude1 = -74.0060; // longitude of position 1

const latitude2 = 34.0522; // latitude of position 2
const longitude2 = -118.2437; // longitude of position 2

const distance = calculateDistance(
  latitude1,
  longitude1,
  latitude2,
  longitude2
);

console.log(`The distance between the two positions is ${distance} kilometers.`);

Thank you - but does this assume the user must type in latitude/longitude co-ordinates, rather than a post-code/zip-code?

No that means, that it was just a part of the whole project.

Of course you will need also a MAP (Google-Map). The google map can handle (longitude and atidude-koordinates) and shows up ADRESS, HOUSE-NUMBER, SETS A LOCATION-POINTER ON THE MAP, nad more.

Of course this will get much more complex, if you want to generate such a functionality on your site.

I don’t think that the Wix-Out-Of-The-Box-Google-Map will be able to handle this (maybe it will work for one MAP-LOCATION-POINT) only. That means → you will have also to generate a whole MAP-SETUP in either a CUSTOM-ELEMENT, or using a HTML-Component.

And this means you also will have to establish a communication between VELO and HTML-Component.

A lot of work and a big project.

But maybe you also can use the Wix-Ordinary map.
But it provides only this API-FUNCTION…
https://www.wix.com/velo/reference/$w/googlemap/location

ADDITIONAL-INFO:
If you want to generate a real good MAP-FUNCTION (by using an HTML-COMPONENT or a CUSTOM-ELEMENT) —> you will need a PREMIUM Wix-Website.