# Concept for 5km delivery constraint & time taken to travel

**URL:** <https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946>\
**Category:** Ask for Help\
**Created:** [May 12, 2020, 1:56am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946 "2020-05-12T01:56:58Z")\
**Posts on this page:** 12\
**Page:** 1

<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 12, 2020, 1:56am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/1 "2020-05-12T01:56:58Z")

</div>

Hi Gliders,

Inspired by this posts regarding how some businesses can’t offer a delivery outside their 5km radius.

> [@Postcode verification before purchasing (happy to hire an expert)](https://community.glideapps.com/t/postcode-verification-before-purchasing-happy-to-hire-an-expert/8581):
>
> Guys, I really need your help and I’m happy to pay a Glide Expert if he can help me sort this problem out. The type of services that I supply is location-specific. This means that I won’t be able to cater to customers that exceed 5km my base location. How can I tweak the Spreadsheet to achieve this? Or perhaps there are alternative methods to achieve the same through Stripe (e.g. blocking rules)? Thanks and, again, if you are an expert please let me know and I will be happy to work with you…

I developed a solution to calculate distance between customer’s input address and  
the business’ fixed address. The use of postcode was proposed in some threads, but I don’t think it would have the same effect as taking the exact distance via Google.

**My test app link:** **[geocodetest.glideapp.io](http://geocodetest.glideapp.io)**

Demonstration video:

![ezgif-1-223b6941057e](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/2X/9/947ee69016084d52b9e9d004127996bfa376b2d2.gif)

User flow:

- Sign in via mail, if user has not filled their name, address and phone number, order options won’t be shown. They can fill up those information via the Profile tab. Thanks @Robert_Petitto for his instructions on this!

- Once they have “signed up”, a small profile of them will be shown on the top of the “Dishes” tab, containing their address, how many minutes it takes to deliver to them, and a message for them to see if delivery is available for their address or not.

- If they are more than 5km away, the options for ordering won’t be shown, and vice versa. They can edit their address and phone number via the item in “Dishes” tab as well, and it takes some seconds for recalculation once they have entered a new address.

- I did not develop the further steps in the process (ordering, add to cart, etc.) since this is concentrated on how to restrict orders outside of a certain radius.

Data flow:

- Address, phone number, email and avatar (avatar is not required) will be assigned to a “User Profile” tab in the Sheets.

- The script I used will be in charge of calculating the distance and travel duration for user’s address to the fixed business address. For demonstration, the fixed address was set to “Santiago Bernabeu Stadium”.

- When the user edits their delivery info in the “Dishes” tab, their user profile info will be edited as well. Next time they log in, the address will be the last one they used.

- Calculation of distance and travel time will be done automatically thanks to another script that copies the formulae down (since they do not work with arrayformula).

This was done with the help of Google Scripts. If any people want to integrate this to their app, please drop me a message here or via email [ariesarsenal@gmail.com](mailto:ariesarsenal@gmail.com).

---

<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 12, 2020, 1:57am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/2 "2020-05-12T01:57:46Z")

</div>

Thank you so much to @Robert_Petitto and @Jeff_Hager, I struggled with the flow at first but ultimately I think I made it good enough to integrate to whoever needs 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 12, 2020, 2:05am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/3 "2020-05-12T02:05:59Z")

</div>

Hi @Robert_Petitto, I just checked your input, it seems like when you are too far away (like USA and Spain) in this case the script can’t return a value.

When I changed the fixed address to an address closer to your input, it worked.

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [May 12, 2020, 2:08am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/4 "2020-05-12T02:08:05Z")

</div>

Nice. I’d like to see this work dynamically. Get the distance between two people, let’s say. Only thing is that scripts can’t see Glide data columns.

---

<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 12, 2020, 2:10am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/5 "2020-05-12T02:10:13Z")

</div>

Yeah, currently there’s no way to get Glide data back to script so that’s it.

Furthermore, if we can get the value of user’s current location then this would make the flow better. Users don’t have to manually enter the address anymore.

---

<div class="post-metadata">

**Author:** ![garrison](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/garrison/32/22059_2.png) [@garrison](https://community.glideapps.com/u/garrison)\
**Post date:** [May 12, 2020, 8:08pm UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/6 "2020-05-12T20:08:34Z")

</div>

@ThinhDinh: This is amazing, thank you for sharing such detailed flows!

For our use case, we’re looking to do something along similar but less complex lines, i.e. enable users to search venue listings x miles/hours distance to venues from whatever town/city or postcode they enter, e.g. 2 hours from London, or 50 miles from Manchester etc.

Does the key to making this work lie in Google Scripts?

---

<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 12, 2020, 11:07pm UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/7 "2020-05-12T23:07:03Z")

</div>

Yes, it lies in the scripts. If you’re interested, drop me a personal message or email me and we can discuss about setting it up for you.

---

<div class="post-metadata">

**Author:** ![garrison](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/garrison/32/22059_2.png) [@garrison](https://community.glideapps.com/u/garrison)\
**Post date:** [May 13, 2020, 7:47am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/8 "2020-05-13T07:47:39Z")

</div>

@ThinhDinh: Thanks, I may take you up on that but right now we’re getting all our ducks in order first as the distance feature isn’t a ‘must have’ for the app at the moment.

---

<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 13, 2020, 8:06am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/9 "2020-05-13T08:06:10Z")

</div>

No worries, feel free to contact me when you need to implement it.

---

<div class="post-metadata">

**Author:** ![garrison](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/garrison/32/22059_2.png) [@garrison](https://community.glideapps.com/u/garrison)\
**Post date:** [May 13, 2020, 8:21am UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/10 "2020-05-13T08:21:07Z")

</div>

@ThinhDinh: thank you! Yes, it will be best when we have a few listings to experiment with.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [May 13, 2020, 3:38pm UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/11 "2020-05-13T15:38:40Z")

</div>

Nice job @ThinhDinh

I was doing something similar but I stopped it due to I had to finish another project. Good to see this idea working fine on other APPs

Let me share my original idea (what I had developed so far to compare to yours):

1. I saved all my customers (stores/places) in my GS along with their coordinates (I supposed that working with coordinates instead addresses the searching will be faster and more accurate, it was my plan B)
2. The user writes his address using an Entry Text Field and the searching begins. I let the user use any address instead using the one used in his profile (just a matter of style, no problem)
3. Using an own function in GS I look for distances (Km) from User address to my customers (each one), something like  
`=DistanceKm(UserAddress, CustAddress)`
4. via Query() I get the 4-5 closest places/stores (I could show more places but I was thinking as my user on my APP) and show those few options on screen
5. I was thinking of letting a choice component to set the distance to search. I mean, my scope searching could be:

- 2 Km
- 4 km
- 7 km
- 10 Km  
to give more chances to my user to decide where to go or ask for. Again, it’s just a matter of style.

I stopped my APP at step 4 so far but I wonder if your APP was using the same way I was thinking days ago (I use Query() instead of filters and other things than make any sheet something bigger)??

Thanks  
Feliz día!

---

<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 14, 2020, 12:11pm UTC](https://community.glideapps.com/t/concept-for-5km-delivery-constraint-time-taken-to-travel/8946/12 "2020-05-14T12:11:53Z")

</div>

Hi Gustavo, nice idea you have there.

I agree that coordinates would present a more accurate solution, that’s for sure. That’s why getting current user’s coordinates would give our ideas much better results.

At first I got the user to write his address, that would change per order, but later changed it to this. Yeah it’s a matter of style, no problem.

I like your idea, let me know if I can help.
