Is `matchedGeoLocation` being rounded or truncated somehow?

Hi there,

I’m trying to match the _rankingInfo.matchedGeoLocation with the associated item in my _geoloc array. However, it appears that the matchedGeoLocation is being truncated, or rounded in some weird way. Here’s an example:

Search query:

index.search("", {
  "getRankingInfo": 1,
  "facets": "*",
  "attributesToRetrieve": "*",
  "highlightPreTag": "<em>",
  "highlightPostTag": "</em>",
  "hitsPerPage": 10,
  "aroundLatLngViaIP": true,
  "facetFilters": [],
  "maxValuesPerFacet": 100
});

Response: (truncated for brevity)

...
{
  "id" : 83368,
  "_geoloc" : [{
    "lat" : 37.8104485,
    "lng" : -122.2398636
  }],
  "_rankingInfo" : {
    "nbTypos" : 0,
    "firstMatchedWord" : 0,
    "proximityDistance" : 0,
    "userScore" : 81779,
    "geoDistance" : 227,
    "geoPrecision" : 1,
    "nbExactWords" : 0,
    "words" : 0,
    "filters" : 0,
    "matchedGeoLocation" : {
      "lat" : 37.8104,
      "lng" : -122.24,
      "distance" : 227
    }
  }
}
...

Can someone tell me why _geoloc[0].lat and _rankingInfo.matchedGeoLocation.lat are not the same? In some other cases, they’re not even rounding properly. (I found that 37.812882 was being “rounded” to 37.8128.)

Thanks in advance for the help!

– Adam

Hi Adam,

The documentation around matchedGeoLocation can be found in the docs. In there, it states that the matchedGeoLocation is the Geo Location that matched the query.

My guess is that the engine will try to match the _geoloc to a valid location that it knows about, and then will use it in order to get the proper Geo information (distances and such).

Under the matchedGeoLocation object, there is the distance parameters which is the distance between the matchedGeoLocation and the search location _geoloc docs.

I’m not sure you understood my question. Shouldn’t matchedGeoLocation and _geoLoc be identical?

@guy.daher: can you help clarify this? I would really appreciate it!

Hey @ad1, very sorry I didn’t get a notification for your previous reply. Thanks for tagging me.

To explain what I mean, I will give a small example/analogy:

Imagine a straight horizontal line with coordinates [1,5], [2,5], [4,5].
These are the coordinates that the Algolia service knows about and that it uses to compute the distances.

Now imagine that you give query with coordinates of [1.3,5]. The Algolia service will match to the closest coordinates that it knows about, which is [1,5] since 1,3 is closest to 1 than 2. (rounding it down).
Now imagine you give it coordinates of [3.2,5]. 3.2 is closest to 4 than to 2. So the Algolia service will map it to [4, 5] (rounding up).

My point is, the Algolia service will not focus on “rounding”, but focus more on mapping the given coordinates that you give it, to some “matched” coordinates that it stored previously and knows about in order to do the proper distance computations.

Let me know if you want me to try a different way to explain :slight_smile:

Sorry to bump an old thread but I need a little more explanation.

I’m finding that, if I take known _geoloc coords of a given record and use those values to perform a geo search using aroundLatLng and an aroundRadius of 1, I’m not getting that record.

In one example, I have a record with a _geoloc lat/lng of 34.811674, -92.488932. I don’t get that record with a geo search until I bump aroundRadius to 11m. The matchedGeoLocation is 34.8116, -92.489 with a distance of 10m.

The distance between the actual _geoloc coordinates of a record and the matchedGeoLocation differ for each record and, because the locations Algolia “knows about” are unknown, it’s impossible to set an aroundRadius that gets you predictable results.

It seems that the coordinates Algolia “knows about” should be derived or at least include known coordinates from the records in the index.

Hi @bdelancey,

Thank you for contacting us.

The internal geoprecision of the engine is currently 10m, we unfortunately don’t index more.
One potential improvement we may do in the future is to allow adding metadata.