diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 86e5c9e87..ae9ecc0ca 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -87,7 +87,15 @@ template class GeospatialQuery : std::make_pair(true, true)); return valid; }); - return MakePhantomNodes(input_coordinate, results); + auto phantom_nodes = MakePhantomNodes(input_coordinate, results); + // there is no guarantee that `SearchInRange` will return results sorted by distance, + // but we may rely on it somewhere + std::sort(phantom_nodes.begin(), phantom_nodes.end(), [](const auto &lhs, + const auto &rhs) + { + return lhs.distance < rhs.distance; + }); + return phantom_nodes; #endif } @@ -338,11 +346,6 @@ template class GeospatialQuery distance_and_phantoms.begin(), [this, &input_coordinate](const CandidateSegment &segment) { return MakePhantomNode(input_coordinate, segment.data); }); - std::sort(distance_and_phantoms.begin(), distance_and_phantoms.end(), [](const auto &lhs, - const auto &rhs) - { - return lhs.distance < rhs.distance; - }); return distance_and_phantoms; }