I'm trying to get a result in nautical miles between two lon/lat saved in a point data type field in mySQL. However, the result seems to be not in any unit I'm familiar with (maybe degrees). How can I convert to my preferred unit?. My query as follows…
select t1.id, t2.id, ST_Distance(t1.test,t2.test) as DistanceApart from table1
t1 join table2 t2 on (ST_Distance(t1.test,t2.test) <= 10)
Best Answer
ST_Distance
assumes a flat surface and returns a distance in the same units as the "Points" that are fed to it.You want
ST_Distance_Sphere
. It takes an optional argument, which you should give as the radius of the earth in nautical miles. Suggest 3440.But note: That function was not implemented until Version 5.7.6. (Not yet in MariaDB)