Hi Team,
Do you know if it’s possible to implement functionality to sort locations by distance closest to the user after scrolling on the map?
As I understand the logic currently, when searching for a location (with distance sorting applied in the search config), results will be returned based on ascending distance to the user within the vicinity of the search. This means that searching for “locations in Chicago” will display results in Chicago and then the algorithm will sort the results based on distance to the user.
However, if the user moves around on the map, the search “reruns” and now the search results are sorted based on distance from the “center of the search”. Is it possible to update that logic so that even when a user scrolls around and looks around on the map, they are able to search for locations nearest to them?
Best,
Hamid Hafiz
Hi Hamid,
Thanks for your submission. The reason why you are seeing those results are because with Place Search, we always rank results by distance to the filter, ascending. For instance, if I’m located in New York and search for ‘best restaurants in LA’, I’d probably expect to see restaurants closest to the centroid of LA returned, rather than a bunch of restaurants on the outskirts of LA or even outside of LA returned first.
We can follow up with engineering on potential workarounds, but one thing you can try doing in the meantime is to see if you can add some conditional logic to the frontend that checks whether the distanceFromFilter
param in the API response exists and if so we display that on the card, otherwise we fall back to displaying distance
. What this does is it should remove some of the confusion around seeing the card display a different distance metric (distance to user) than the one used in the ranking (distance to filter).
Let me know if that helps!
Best,
Chris