# Multiple location distance calculation

**URL:** <https://community.glideapps.com/t/multiple-location-distance-calculation/61350>\
**Category:** Ask for Help\
**Created:** [May 4, 2023, 4:08pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350 "2023-05-04T16:08:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 4, 2023, 4:08pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/1 "2023-05-04T16:08:24Z")

</div>

Hi so i am working with a logistics company that want to pass multiple locations into a system where it will then calculate the distance between those locations.

Here is what the page could look like: (blurred out parts are the locations)

 ![SCR-20230504-pvih](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/6/6673baeeac03a6496252840d4051433c1972b441.png)

Now here is my problem. I know that there is a distance between column in glide and I know that I can have multiple of these and then just calculate them all together with a formula.

Do any of you know of a better way to do this. I am also a little bit experienced with api calls.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 4, 2023, 4:30pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/2 "2023-05-04T16:30:38Z")

</div>

I haven’t tried it yet myself, but I believe that the [Radar Integration](https://www.glideapps.com/docs/reference/integrations/radar#distance-between-locations) can do this.

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 4, 2023, 4:35pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/3 "2023-05-04T16:35:20Z")

</div>

Are you saying that I can add more than 2 destination into the radar column.

As I only see origin and destination.

 ![SCR-20230504-qfie](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/c/dc9ba7221ee276b813845a860c16bf0f72d14d96.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [May 4, 2023, 4:56pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/4 "2023-05-04T16:56:40Z")

</div>

ah, I see.

So you’re basically looking to calculate the total distance in a single step. And I guess the challenge might be that there could be an indeterminant number of intermediate stops, yes?

I think my approach to this would be to use a Helper Table to arrange the route stops into rows, use a single column to calculate the distance between each stop (1st to 2nd row, 2nd to 3rd row, etc), and then use a rollup to calculate the total.

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 4, 2023, 5:20pm UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/5 "2023-05-04T17:20:06Z")

</div>

That was my approach before posting in the community. I am wondering if its possible to send these locations as an array into airtable where I can run a script to calculate the distances.

But I see the webhook is unable to take an array

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [May 5, 2023, 12:26am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/6 "2023-05-05T00:26:56Z")

</div>

What about a delimited list of locations, and then you split that into an array later on when it gets to Airtable?

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 5, 2023, 6:37am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/7 "2023-05-05T06:37:01Z")

</div>

What do you mean by delimited list? Sorry I am pretty new to this.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [May 5, 2023, 8:47am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/8 "2023-05-05T08:47:24Z")

</div>

I mean passing something like “Location A,Location B,Location C” and then you do your magic on the Airtable side. Would that work?

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 5, 2023, 8:49am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/9 "2023-05-05T08:49:39Z")

</div>

Oh yes, that what i was working on. But I would have preferred if I could do it in glide as doing things in airtable is really slow. I wish we could pass arrays into the js column

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [May 5, 2023, 8:55am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/10 "2023-05-05T08:55:05Z")

</div>

Would passing the list above works for the JS column, then you use a split function to split that into an array?

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 5, 2023, 9:28am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/11 "2023-05-05T09:28:20Z")

</div>

That can work. I really think glide should spend more time with the JS column. Limited Inputs and no popup code editor.

---

<div class="post-metadata">

**Author:** ![Bradley\_Gibson](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/bradley_gibson/32/58297_2.png) [@Bradley\_Gibson](https://community.glideapps.com/u/Bradley_Gibson)\
**Post date:** [May 5, 2023, 9:39am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/12 "2023-05-05T09:39:13Z")

</div>

So this is what I cam up with.

The locations are set as an array and then the JS looks for the first and last entries in the array that sets them as Origin and Destination, with the rest being set as Waypoints.

```auto
  var origin = locationsArray[0];
  var destination = locationsArray[locationsArray.length - 1];
  var waypoints = [];
  for (var i = 1; i < locationsArray.length - 1; i++) {
    waypoints.push({location: locationsArray[i]});
  }

```

---

<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:** [May 6, 2023, 9:39am UTC](https://community.glideapps.com/t/multiple-location-distance-calculation/61350/13 "2023-05-06T09:39:53Z")

</div>

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