Is this possible, how? It's like zomato restaurant finder

Hii I want to make a page where I will add about 500 hundred restaurant names with there descriptions , and if user living in Manhattan in New York City , opens the page , the page should display restaurant available in that place from the 500 restaurant and after that it should show many more , how can I do that

  1. First get the users location, you can do this in the wix-window here wix-window-frontend - Velo API Reference - Wix.com.

  2. Then you need to get the longitude and the latitude from the above and then get the distance between your user and all data in your data collection. If you have stored addresses on all restaurants you can calculate distance between all those records and the current user.

Then you need some code to convert an address from your data collection to longitude and latitude. I often use this one.

After you have the longitude and latitude from each and every record on your loop you have to calculate distance.

function distance(lat1, lon1, lat2, lon2, unit) {
var radlat1 = Math.PI * lat1/180
var radlat2 = Math.PI * lat2/180
var radlon1 = Math.PI * lon1/180
var radlon2 = Math.PI * lon2/180
var theta = lon1-lon2
var radtheta = Math.PI * theta/180
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
dist = Math.acos(dist)
dist = dist * 180/Math.PI
dist = dist * 60 * 1.1515
if (unit=="K") { dist = dist * 1.609344 }
if (unit=="N") { dist = dist * 0.8684 }
return dist
}

Use that code with

var distance = distance(51.5112139, -0.119824, 48.8567, 2.3508, ‘K’);
//round to 3 decimal places
console.log(Math.round(distance*1000)/1000); //displays 343.548

Then you have the distance and you can then present the results on your page sorted by distance. If you want to speed up your page along the way I usually store the LAT and LNG cordinates in the data collection after I got them the first time or even better, find them after save and store them right away. Will speed up page mucho mucho.

Do you tag along?

Awesome :slight_smile: