-
Notifications
You must be signed in to change notification settings - Fork 66
Description
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.
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).
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).
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.
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.
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




