Forum Academy Marketplace Showcase Pricing Features

Distance calculation User -> Place

Hello, for application purposes I am looking to create a system where users can search for places by distance.

I do not use a plugin referring to google api or other

I have a User table with common (text) latitude (number) and longitude (number) fields.

I have another Place table where I have different fields including latitude (number) and (longitude) number.

With the Ultimate Toolkit plugin I would like to create a workflow when I click on a button calculates the distance between a user and the different Places, knowing that I have 9000 Places. Maybe I should save the result of this query in a user field?

Can you tell me if my screenshot below is good and what is missing in the to List function as I can’t seem to get past it.

Thanks for your help

A few days ago I came across this link

I think that corresponds to my research but I stumble on bubble logic

Here is the excerpt that interests me

If the location of the things is stable you could store the distances in the database.

"
How to do it:

Create a new datatype “Relation” that will include reference to two things and a distance field.
Create a backend workflow that is triggered when a new thing is added. The workflow should iterate all things and create “Relations”.
then you can use “Relation” for sorting.
If it is not your use case and you need to calculate the distance every time within a certain radius then a different a bit more complex approach could be used. It requires more explanation. Let me know you need it. "

So I created a new type called relationship with this inside.

Does my distanceresult field have to be a number

And now I don’t see how I can fill this in my workflow

help please :slight_smile:
thanks

1 Like

If you can set a max radius for the search you won’t need then iterate 9000 places - just those that are within the max radius. Your data structure looks correct. You would need to create a backend workflow to calculate the distances.

Hi @shpak.serhiy

all my searches on “radius” send me tutorials where they talk about it but with the google API. I can’t find how to calculate the radius with ‘Ultimate toolkit’, you wouldn’t have a screenshot or a walkthrough or video for that?

Thx

It is a bit complicated to describe it in short and clear. Let’s say you need to calculate the distance from A to B(n).
The trick is to filter and sort all B(n) by longitude and latitude in relation to A
You need to run a recursive workflow on the list of things to which you want to calculate the distance.
You will have 4 lists of Things:

  1. Lon B > Lon A | Lat B > Lat A
  2. Lon B < Lon A | Lat B < Lat A
  3. Lon B < Lon A | Lat B > Lat A
  4. Lon B > Lon A | Lat B < Lat A

As the Bs are sorted in the lists the workflow will process them not randomly but starting from the center (A). Once the workflow exceeds the radius it stops.

So you might have 9000 things in your DB. But for instance, in a 50 km radius, there might be 9 things and those things could be found almost instantly and without engaging paid APIs.

1 Like

Thank you for your help and your patience. I’ll see how I can get out of this!