# Distance between 2 places via

**URL:** <https://community.thunkable.com/t/distance-between-2-places-via/1694120>\
**Category:** Questions about Thunkable X\
**Tags:** beginner\
**Created:** [January 25, 2022, 11:56am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120 "2022-01-25T11:56:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 25, 2022, 11:56am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/1 "2022-01-25T11:56:12Z")

</div>

Hi,

I would like to calculate distance between two places where user should be able to enter the from and to, where the app should show the distance between those two places. Is it possible?

Your input is highly appreciable!

Regards,  
Sasi Preetha

---

<div class="post-metadata">

**Author:** ![Dean\_Artis](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Dean\_Artis](https://community.thunkable.com/u/Dean_Artis)\
**Post date:** [January 25, 2022, 12:02pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/2 "2022-01-25T12:02:59Z")

</div>

What have you tried so far?

Will the user select their start and end points from Google Maps or some other way?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 25, 2022, 1:27pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/3 "2022-01-25T13:27:23Z")

</div>

Check this post

> [@API Distance Matrix does not work on thunkable x](https://community.thunkable.com/t/api-distance-matrix-does-not-work-on-thunkable-x/1102596):
>
> Hi Everyone, I am trying to get the “distance” and the “duration” from google maps distance matrix API, but it is not working. The blocks are shown below: On the browser, it works: [image] I get the “200” status, but: On IOS and Android test I get this error message: I think is a thunkable error… can someone help me please? Thank you so much!

---

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 25, 2022, 1:56pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/4 "2022-01-25T13:56:51Z")

</div>

Its working if we pass lat and lng for from and to place via formula. ( i got that from Thunkable community too:)) [Thunkable](https://x.thunkable.com/projects/61f001c3296e6a0012be6c8f/0b2f327e-55c3-48c3-93e4-a845e3f1632a/designer)

But I would like to pass the places instead of lat and lng.

---

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 25, 2022, 2:25pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/5 "2022-01-25T14:25:50Z")

</div>

Yes Muneer, I saw that post before I post here but google map Distance Matrix API does not work for me, it says invalid api key.

I am trying [Route Matrix API Playground | Geoapify](https://apidocs.geoapify.com/playground/route-matrix) where it has to be via POST.

How to do it via POST?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 25, 2022, 2:32pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/6 "2022-01-25T14:32:18Z")

</div>

> [@sasi.preethag3yh](#):
>
> How to do it via POST?

In the `Web API` component, choose **POST** instead of **GET**. You will need to fill the required information as directed by the documentation.

In the `Headers`:  
Content-Type = application/json

The details of your start and end location goes in the `Body`.

See this example

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/c/bc0ce793756c060cd2ac2ac63117604174b31084.png)

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 25, 2022, 7:32pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/7 "2022-01-25T19:32:55Z")

</div>

This can be done most easily using a backend like backendless or xano

They offer geoquery abilities out of the box!

You can complete this client side but you’ll eventually end up with excessive data pulls at times. Figuring out what’s close to you works well when you’re dealing with maybe 50 to 100 data points. However if you have data points all across your country for example and there’s thousands of them you’re not going to want to do it dad a pool every time. You shouldn’t

@muneer has a great example as well!

I think that using a DB is still a nicer option though can be costly. Using a DB to do these actions will return not only the closest points but can also return other information about those points so you don’t need to do a second query against the retuned spots to return information about the POI’s within your radius.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [January 25, 2022, 7:39pm UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/8 "2022-01-25T19:39:16Z")

</div>

If you have a list of lat/lon pairs, you can also do this within the app using the **Haversine formula** (search the forums for it). That’s what I did for my Air Quality app to allow the user to find the closest Purple Air sensor.

It’s a bit of a pain to set up but it works great and fast and doesn’t require any data pulls (if you already have the pairs data).

But it sounds like you don’t want to deal with lat/lon and prefer “places” so maybe that’s not an option.

---

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 26, 2022, 9:19am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/9 "2022-01-26T09:19:31Z")

</div>

I tried that tatiang. It’s giving correct distance. As you said its fast.

I am able to pass only one lat/lng i.e from(using location sensor) , how do I get the lat/lng of to(destination)?

---

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 26, 2022, 9:26am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/10 "2022-01-26T09:26:18Z")

</div>

Thank you Jared. This sounds tough.

---

<div class="post-metadata">

**Author:** ![sasi.preethag3yh](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@sasi.preethag3yh](https://community.thunkable.com/u/sasi.preethag3yh)\
**Post date:** [January 26, 2022, 11:30am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/11 "2022-01-26T11:30:07Z")

</div>

Finally I found it:)

Sharing the project link:

[Thunkable](https://x.thunkable.com/projects/61f001c3296e6a0012be6c8f/7a040027-b97f-4d8b-b358-01fca5de2016/blocks)

Thanks all for your guidance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [April 26, 2022, 11:31am UTC](https://community.thunkable.com/t/distance-between-2-places-via/1694120/12 "2022-04-26T11:31:05Z")

</div>

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