# How to get the closest distance to my point

**URL:** <https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117>\
**Category:** Questions about Thunkable X\
**Tags:** map\
**Created:** [September 3, 2020, 9:26pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117 "2020-09-03T21:26:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaiper\_watafai](https://avatars.discourse-cdn.com/v4/letter/v/e36b37/32.png) [@Vaiper\_watafai](https://community.thunkable.com/u/Vaiper_watafai)\
**Post date:** [September 3, 2020, 9:26pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/1 "2020-09-03T21:26:36Z")

</div>

Could anyone help me please?  
How can I get the closest distance between various latitude and longitude?

---

<div class="post-metadata">

**Author:** ![Scene](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/scene/32/46329_2.png) [@Scene](https://community.thunkable.com/u/Scene)\
**Post date:** [September 3, 2020, 10:46pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/2 "2020-09-03T22:46:18Z")

</div>

I’d build it using the Distance Matrix API: [https://developers.google.com/maps/documentation/distance-matrix/overview](https://developers.google.com/maps/documentation/distance-matrix/overview)  
Also you can check this: [http://community.thunkable.com/t/distance-matrix/1340/35](http://community.thunkable.com/t/distance-matrix/1340/35)  
Good luck!

---

<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:** [September 4, 2020, 2:54am UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/3 "2020-09-04T02:54:04Z")

</div>

Great question! I was just Googling this last night and there are definite methods (I’m going to check the example above) but I realized for me… I need to loop through a long list of objects (JSON) to see which is closest to a specific latitude/longitude pair and well, I think my object list would be too long to store in Thunkable. Hmm, maybe I could store it in an Airtable or Google Sheet.

Anyway, interested to see what you can figure out!

---

<div class="post-metadata">

**Author:** ![Vaiper\_watafai](https://avatars.discourse-cdn.com/v4/letter/v/e36b37/32.png) [@Vaiper\_watafai](https://community.thunkable.com/u/Vaiper_watafai)\
**Post date:** [September 4, 2020, 1:14pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/4 "2020-09-04T13:14:27Z")

</div>

Thanks for the reply. I’ll see what i can do.

---

<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:** [October 4, 2020, 2:27pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/5 "2020-10-04T14:27:57Z")

</div>

I’m working on the tutorial for this!!!

[UPDATE]  
you’re looking to get a response like [this](https://api.backendless.com/34292C6A-B3A7-83DD-FF79-EF9E6913F900/FD17E678-AFB3-49F3-9663-8CF8D54CE7C7/data/thunkableLocations?where=distanceOnSphere(%27POINT(-85.73455637260194%2042.46124149689038)%27%2C%20location)%20%3C%20mi(33.48396187841322)%20&props=distanceOnSphere(%27POINT(-85.66061443893842%2042.375649975692355)%27,%20location)%20*%200.000621371%20as%20milesToPoint,city,state&sortBy=milesToPoint) back, right?

i create the milesToPoint property everytime the database is called using the URL scheme above.  
i include only milesToPoint,state,city,objectId. everything done very quickly by the DB server. The search was conducted using arbitrary coordinates near my home!

 ![Screen Shot 2020-10-04 at 1.00.51 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/5/b5a214f45bce5483dca28525fe35ce3ecc69b7fe.png)

without any fancy querying the response looks like this.

 ![Screen Shot 2020-10-04 at 1.05.47 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/a/2ad3e8ba13ea8df79d4b1b663a87586a99793550.png)

---

<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:** [October 4, 2020, 9:57pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/6 "2020-10-04T21:57:53Z")

</div>

I’m using the formula posted here: [Calculate distance travelled](http://community.thunkable.com/t/calculate-distance-travelled/565278/2).

I cycle through a list of lat/lon pairs to see which is closest and it works great. No API needed.

---

<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:** [October 4, 2020, 11:22pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/7 "2020-10-04T23:22:50Z")

</div>

🦾.

Makes sense! I am creating a photo sharing app and wanted users to see/search for photos taken near them. The DB is always going to grow so I need the api. For a fixed data set, I’d take your rout too!

My backend does the heavy lifting way faster than any phone will (for now) Whatever works though! Each use case is unique!!

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:23pm UTC](https://community.thunkable.com/t/how-to-get-the-closest-distance-to-my-point/791117/8 "2024-11-08T12:23:35Z")

</div>


