My database has an organisation
tables with two decimal columns lat
and lon
that indicate the location of the organisation. I'm trying to find all organisations within 800km of the coordinate 53.6771, -1.62958
(this roughly corresponds to Leeds in the UK).
The query I'm using is
select *
from organisation
where (3959 * acos(cos(radians(53.6771)) *
cos(radians(lat)) *
cos(radians(lon) - radians(-1.62958)) + sin(radians(53.6771)) *
sin(radians(lat)))) < 800
However this returns locations in Lyon, France which is about 970km from Leeds, UK. I realise that formulae such as the above make some simplifying assumptions (e.g. treating the shape of the Earth as a sphere), so I don't expect the results to be absolutely accurate, but I should be able to do better than this?