I'm trying to implement a geospacial search in a php application. Currently, I'm using the following query to find points within 10km of a given latitude and longitude:
SELECT * FROM (
SELECT *,
(6378.1 * ACOS(
COS(RADIANS(48.856614)) * COS(RADIANS(latitude))
* COS(RADIANS(2.3522219) - RADIANS(longitude))
+ SIN(RADIANS(48.856614))
* SIN(RADIANS(latitude)))
) AS distance
FROM `destinations_info`
WHERE latitude BETWEEN 48.856614 - (10 / 69)
AND 48.856614 + (10 / 69)
AND longitude BETWEEN 2.3522219 - (10 / (69 * COS(RADIANS(48.856614))))
AND 2.3522219 + (10 / (69 * COS(RADIANS(48.856614))))
) d
WHERE distance <= 10
LIMIT 1
This works fine as long I don't search for the exact latitude and longitude that is stored into the POI's table.
So for example if I have in my poi table the following entry
id name latitude longitude
1 Paris 48.856614 2.3522219000000177
And I call the query with lat = 48.856614
and long = 2.3522219000000177
I won't get any results. As far as I see this happens because the following operation returns NULL and not 0 in mysql:
SELECT (6378.1 * acos(cos(radians(48.856614)) * cos(radians(48.856614)) * cos( radians(2.3522219) - radians(2.3522219)) + sin(radians(48.856614)) * sin(radians(48.856614))))
Running the same in Chrome Calculator I get 0 rad.
Is there something wrong in the query or do I need to include the NULL results as well using "OR IS NULL"