MySQL geospacial search using haversine formula returns null on same point

删除回忆录丶 提交于 2019-12-06 07:56:02

IFNULL( ... ),0) AS Distance will also help you to get around the error.

The problem is that acos is invoked with a value which is not in the range of -1 and 1, so it returns null.

SELECT cos(radians(48.856614)) * cos(radians(48.856614)) * cos( radians(2.3522219) - radians(2.3522219)) + sin(radians(48.856614)) * sin(radians(48.856614))

1.0000000000000002

It seems to be some sort of rounding issue.

Since, arc cos is defined only between -1 and 1, you probably should pre-check its parameter or be prepared that it can return null if something is wrong with the calculation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!