Sort listings by distance


I am interested in how I can sort listings by distance from the user’s current location.

I have food listings that contain the following information:

  1. The restaurant to which the dish belongs
  2. The date when the dish is on the menu
  3. Description of the dish

Now, I would like the order in the repeating group to be according to the distance from the user. Food and Restaurants are two different data types, but Food has a connection to which restaurant it belongs to. The address of the restaurant is stored in Restaurant data typ.

Thanks for the help!

You can sort the repeating group only by the existing fields.

I would build it like this:

  • create a new data type “Restaurant-User” with the fields: Restaurant, User, Distance (number).
  • you will need to get the User’s address as well.
  • transform the geographical address (Google Maps location) into coordinates (latitude, longitude). Create on Restaurant and User data types two fields: Longitude (number) and Latitude (number). Longitude and Latitude data can be extracted from the geographical address. Add additional step for the workflows that creates/updates Restaurants and Users that will make changes to thing and write the Longitude and Latitude. Also you would need to add coordinates to all existing Users and Restaurants. For this, create the simple backend workflows that takes User/Restaurant and make changes to them by writing the coordinates.
  • Now all Users and Restaurants have the coordinates. Install the free Ultimate Toolkit plugin Ultimate Toolkit Plugin | Bubble . It instantly calculate direct distance between two points by taking the coordinates.
  • Final step. When the User search for Restaurant run a backend workflow on a list that takes a Restaurant and creates Restaurant-User record and calculates the distance between the Restaurant and the User. As the result you will have a list Restaurant-User records that you display to the User in repeating group. You can sort it by distance. Any info about the Restaurant you can show in this repeating group because Restaurant-User record is connected to Restaurant.

1 Like

Will this work for every new User that searches for a Restraurant?

Can you explain this further?

What exactly is not clear in my description?

Will this work for every new User that searches for a Restraurant?