I want to implement Nearest Place available to User algorithm in Java or MySQL.
I have Stations table in MySQL database which has around 100K records of Stations with Latitude and Longitude. If User gives his latitude and longitude as x and y, then I want to return nearest stations available from User's location.
So please suggest me any algorithm available in Java or MySQL.
I tried with the following query, but it seems slower in performance -
SELECT *,3956*2*ASIN(SQRT(POWER(SIN((user_lat-abs(st.station_lat))*pi()/180/2 ), 2) + COS(user_lat*pi()/180)*COS(abs(st.station_lat) *pi()/180)*POWER(SIN((user_lon-
st.station_lon)*pi()/180/2 ),2))) AS distance FROM Stations st HAVING distance < 10 ORDER BY distance;
Thanks in advance.