# Distance beetwen many relation in 2 tables

**URL:** <https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502>\
**Category:** Ask for Help\
**Created:** [September 25, 2023, 10:13am UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502 "2023-09-25T10:13:30Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 10:13am UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/1 "2023-09-25T10:13:30Z")

</div>

Here is my question: I have two tables with different addresses. I have created a relationship to be able to calculate a distance between them. However, when I create relationships based on streets, I get multiple results, but I cannot calculate the distance between each address. The goal is to be able to, from table A, find all the addresses in table B that are at a certain distance. Is this possible in Glide? Thank you.

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [September 25, 2023, 1:10pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/2 "2023-09-25T13:10:22Z")

</div>

> [@waouhh\_agency](#):
>
> The goal is to be able to, from table A, find all the addresses in table B that are at a certain distance.

“That are at a certain distance” from what?

I’ll assume that the user is in transport and would like to identify which locations within a list of n locations is within x distance, and the current location of the user is not fixed.

**Layout Editor**

- Attach the tab either to the User table or its own table (which I called Current Location Tab)
- Add a Location component
- Add a collection of Locations

 ![Screenshot 2023-09-25 at 14.52.29](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/a/5a5d1af8d8edd8d36cb278db8e7cf43c6212a300.png)

**Data Editor**

- In the Current Location Tab table: Create a CurrentLocation basic text column
- Create a Locations table:
  - Name (basic text),
  - Address (basic text),
  - LatLong (basic text),
  - CurrentLocation (Computed → Single Value → Location Tab → CurrentLocation),
  - DistanceWithAddress (Computed → Distance → CurrentLocation → Address),
  - DistanceWithLatLong (same with LatLong instead)
  - If-Then-Else: if DistanceWithLatLong is greater than 5km then false, else true (5km is an example)

 ![CleanShot 2023-09-25 at 15.01.36](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/6/76ab65ab9c0f6eb1f850ca91c4ea4e78b8aeb766.png)

**Back in the Layout Editor**

- Configure your components by pointing fields to the right columns
- Collection:
  - Make sur you set the data source correctly.
  - In Options → Filter Data, filter for If-Then-Else is true.
  - In Options → Sort Data, sort by DistanceWithLatLong is ascending (for example).

Note that in the example of 5km, instead of being fixed inside the configuration of the If-Then-Else column, could be variable, and this variable could be set by the user (number entry component, write to a Radius basic number column, and use this column in the configuration of the If-Then-Else column).

Also note that you can use either DistanceWithAddress or DistanceWithLatLong. You don’t need both, either one will work. DistanceWithLatLong is supposed to be more precise.

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 1:30pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/3 "2023-09-25T13:30:38Z")

</div>

Thank u for your feedback but : I have a business in table A, and I have parking addresses in table B. I would like to know how to make each address in table A give me the closest parking spots from table B. I’ve tried to create relationships, but it gives me multiple results, which is logical, but I can’t know the distance for each. I hope you understand me.

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [September 25, 2023, 1:45pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/4 "2023-09-25T13:45:48Z")

</div>

How many addresses to you have in Table A, in Table B? Is the amount of addresses in Table A and Table B fixed?

The idea is that the user arrives at one of the locations in Table A and based on that information sees with parking spots in Table B are the closest, or the closest?

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 1:52pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/5 "2023-09-25T13:52:13Z")

</div>

Hello, I have a table A with business addresses and a table B with parking spaces, and I would like to know how I can see the parking spaces that are close to the businesses in table A. I tried to calculate the distance, but it only works if there’s a single relationship, and in this case, each business may have multiple parking spaces related to it.

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 1:53pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/6 "2023-09-25T13:53:13Z")

</div>

i think i need to make all the parking for all the shop but its to much time… and i dont know if is possible to make directly in Glide

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [September 25, 2023, 1:54pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/7 "2023-09-25T13:54:43Z")

</div>

How many business addresses are there in Table A? How many parking spots are there in Table B? Is the amount of addresses in Table A and Table B fixed?

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 1:59pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/8 "2023-09-25T13:59:34Z")

</div>

the adress table A change when new user insert is shop, the adresse table B dont move its a data base from city i dont change this only sometimes.

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 2:02pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/9 "2023-09-25T14:02:44Z")

</div>

a explain you : i have make a app for peaple around us can show her shop. a have table for user, table for shop , and table for parking for exemple… i have already make distance beetween user and shop but i need relation table B shop with parking place… i know i can make with google sheet for everyall adress shop and parking but its around 500 parking… and if i make one by one i died…ahahh

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [September 25, 2023, 2:15pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/10 "2023-09-25T14:15:14Z")

</div>

500 parking lots, ouch, I understand your predicament. I don’t have any good ideas, sorry.

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 2:16pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/11 "2023-09-25T14:16:19Z")

</div>

Don’t worry i undestand… i search… if i have solution i post for everydoby… thank u so much for your help. Nice day

---

<div class="post-metadata">

**Author:** ![slscustom.ru](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slscustom.ru/32/77336_2.png) [@slscustom.ru](https://community.glideapps.com/u/slscustom.ru)\
**Post date:** [September 25, 2023, 2:39pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/12 "2023-09-25T14:39:04Z")

</div>

Hello!  
So, this is common google map feature may be, web view its enough?

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 2:42pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/13 "2023-09-25T14:42:07Z")

</div>

hello, yes i can make like that but i need to use glide map it’s more confortable to view directly the places… I try to make calculate with google sheet with Lat/Long and variable for show the parking place and i try to put google sheet to Glide … if you have another solution. nice to you !

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [September 25, 2023, 3:08pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/14 "2023-09-25T15:08:01Z")

</div>

There are two solutions:

- The complicated one would be a JavaScript column in the business  
table that could take in the location of the business and a list of parking locations, create a loop that would mathematically calculate the distance from the business to each parking location, and then return a list of the parking locations that fit your requirements.

- Or, the easy way is to use a set column action to write the business location somewhere in a table, then use a single value column to bring the selected business location into the parking table and calculate distance in the parking table. Then set filters accordingly.

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 3:16pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/15 "2023-09-25T15:16:25Z")

</div>

thank u. i try to make script its work on google sheet ! but i try to calcul directly all the distance on one shop and all parking adress … … So long  
i think its easy for me to make shop by shop and make all parking in the same street… after compiled all in one sheet… i’m thied for this since 3 days i search a solution…  
i’m not far to make the solution but i don’t know why i whant make this possibility on the app … ahah

---

<div class="post-metadata">

**Author:** ![slscustom.ru](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/slscustom.ru/32/77336_2.png) [@slscustom.ru](https://community.glideapps.com/u/slscustom.ru)\
**Post date:** [September 25, 2023, 3:28pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/16 "2023-09-25T15:28:20Z")

</div>

Sorry for my English!  
We can fetch objects like this  
https://overpass-api.de/api/interpreter?data=[out:json];(node(around:1000,55.7558,37.6173)[“amenity”=“parking”];);out;  
then parse addresses and comparing to table and if they persists so to show objects from table

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 3:41pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/17 "2023-09-25T15:41:25Z")

</div>

ok i undestand what you say… i try make possibility… i come back to you… Thanks

---

<div class="post-metadata">

**Author:** ![waouhh\_agency](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/waouhh_agency/32/64464_2.png) [@waouhh\_agency](https://community.glideapps.com/u/waouhh_agency)\
**Post date:** [September 25, 2023, 5:30pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/18 "2023-09-25T17:30:13Z")

</div>

If you whant to make distance ( like 50m ) beetween multitude adress correspondance in Table A to Table B.

- For me the solution **is to use Script from Google sheet and add the table to Glide.**  
If you need the script let me know !

Best, Waouhh

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [October 2, 2023, 5:30pm UTC](https://community.glideapps.com/t/distance-beetwen-many-relation-in-2-tables/66502/19 "2023-10-02T17:30:41Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
