Skip to content

GeoSearch middle point calculation fails on big dezoom #551

@bidoubiwa

Description

@bidoubiwa

⚠️ related to this PR, does not need solving before it is merged #543

Description
GeoSearch works correctly at determining the central point of the box when the view is not dezoomed. How more you dezoom on very big world views, how more you lose in accuracy.

Explaination:
In MeiliSearch, the user provides one geoPoint around which all the search is done. MeiliSearch uses the haversine formula to calculate if a point is inside the radius when the user is filtering.

The problem is that in instant-meilisearch we are provided not with one geo point but two geo points. The reason behind that is that Google Maps provides the upper right geo point and lower left geo point (purple dots on image 1) of the google maps windows.

To be compatible with MeiliSearch, I have to calculate the middle point of these two points (green dot on img). This calculation is done with the formula explained in this article.

Screenshot 2021-10-14 at 13 39 55

The problem that we encounter is that the formula calculates the middle point of the shortest distance between two points. So when I dezoom to much, the center point of two dots does not pass through europe, but through the pacific ocean (img 3).

Screenshot 2021-10-14 at 13 49 22

So when searching for Hardenberg a random city in germany, when my two geopoints have their shortest distance through europe my results are correct (img 2).

Screenshot 2021-10-14 at 13 45 12

But when I zoom too much. The center point is somewhere in the pacific (img 3) and thus using the distance as a radius, I recieve all points around that point.

Screenshot 2021-10-14 at 13 49 22

You can see in the last gif how this becomes a real issue and would make our demo’s look weird if the user dezoom’s too much.

geoproblems

So the solution! Well… I would have said to check if the middle point is somewhere in europe but … the user can always slide to another side of the world.

The only thing that gives a possibility to know where the center of the map is that Google maps provides the left lower corner and the right upper corner.
Whereas, when we calculate the middle point we do not take that into account. Thus, the lower left corner becomes the lower right corner, and the upper right corner becomes the upper left corner.

Here you can find the calculation I have integrated to instant-meilisearch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions