# How to calculate Distance between Geolocation?

**URL:** <https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [May 15, 2020, 6:20pm UTC](https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867 "2020-05-15T18:20:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![murilovictor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/murilovictor/32/68460_2.png) [@murilovictor](https://discuss.elastic.co/u/murilovictor)\
**Post date:** [May 15, 2020, 6:20pm UTC](https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867/1 "2020-05-15T18:20:41Z")

</div>

Hello, I am implementing a geolocation search.

Is there a way for AppSearch to calculate the distance between locations?

I know I can do this search. but is it possible that the result of the consultation shows the distance between the places?

Search Example:

```
"filters": {
    "location": {
      "center": "37.386483, -122.083842",
      "distance": 300,
      "unit": "km"
    }
  }

```

Answer Example.

```
[
   {
      "restaurant": "Restaurant 1",
      "distance": "3km"
   },
   {
      "restaurant": "Restaurant 2",
      "distance": "10km"
   },
   {
      "restaurant": "Restaurant 3",
      "distance": "14km"
   }
]

```

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [June 5, 2020, 11:34am UTC](https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867/2 "2020-06-05T11:34:55Z")

</div>

Hey @murilovictor, is this something that you can do yourself? Since you have the "center" and a location field on each document, you should be able to calculate this.

The one thing I am not sure of that you may want is the ability to sort based on that distance.

---

<div class="post-metadata">

**Author:** ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)\
**Post date:** [June 5, 2020, 4:05pm UTC](https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867/3 "2020-06-05T16:05:07Z")

</div>

Elasticsearch has Geo Sorting, which is not currently available in App Search: [https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-sort.html#geo-sorting](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-sort.html#geo-sorting)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 3, 2020, 4:05pm UTC](https://discuss.elastic.co/t/how-to-calculate-distance-between-geolocation/232867/4 "2020-07-03T16:05:11Z")

</div>

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