-
-
Notifications
You must be signed in to change notification settings - Fork 296
Open
Description
Hi,
I think I’ve found a small issue in TNTGeoSearch::buildQuery().
When using the findNearest function, the distance value calculated in SQL can sometimes be slightly greater than 1.0 if the two coordinates are very close (maybe due to floating-point precision errors?).
Since acos() is only defined for values in the range [-1, 1], this causes it to return NaN, and the nearest location is excluded from the final results.
Suggested fix: Clamp $location['distance'] between -1.0 and 1.0 before calling acos() here:
https://github.com/teamtnt/tntsearch/blob/master/src/TNTGeoSearch.php#L71
$val = max(-1.0, min(1.0, (float)$location['distance']));
$location['distance'] = acos($val) * $this->earthRadius;Happy to open a PR with the fix if it’s helpful.
leonardfischer and zawaze
Metadata
Metadata
Assignees
Labels
No labels