I have a MySQL Table where there are three columns: lat, lon and ID
Now as Input I want user to give a pair of Lat & long. In return, I want to show the sorted rows from closest to farthest.
Now, one solution of this problem is, fetch all entries in an array, make a temp array, calculate distance for each item using haversine formula, push to the temp array, and finally perform any sorting algorithm on that array.
But, this operation is heavy and I want a better solution. Is there any?
P.S: I am using PHP script.