The solution proposed by Chris:
SELECT * AS distance FROM items ORDER BY ((location_lat-lat)*(location_lat-lat))
+ ((location_lng - lng)*(location_lng - lng)) ASC
is correct when we are close to the equator. For it to work correctly in other latitudes, I propose:
SELECT * AS distance FROM items ORDER BY
((location_lat-lat)*(location_lat-lat)) + ((location_lng
- lng)*(location_lng - lng)*cos_lat_2) ASC
where we must precompute:
cos_lat_2 = cos(location_lat * PI / 180) ^ 2
THE PROBLEM:
If we are in the equator and we move one degree in longitude (east or west), we do so on a circumference of 40,000 km, representing a distance of 40.000 / 360. If we move one degree in latitude (north or south), we do so on a circle that crosses both poles, which also involves a distance of 40.000 / 360 (considering that the earth is a sphere).
But, if we are in the south of England, with a latitude of 50°, and we move one degree in longitude (east or west) we do it on the 50th parallel, which has a smaller circumference than the equator. The distance is perimeter_parallel_50 / 360. Calculating this perimeter is simple: perimeter_parallel_50 = cos (50) * 2 * PI * EARHT_RADIUS = 0.64 * 40,000 km. This reduction in distance is not seen if we move one degree south or north. The circumference by which we move still has a perimeter of 40,000 Km.
SOLUTION:
Since location_lat is a value known beforehand, we can pre-calculate the value of cos(location_lat) so that it can be used as a scaling factor so the displacements in longitude and latitude are equivalent. Moreover, we pre square it to avoid having to multiply it twice.
NOTE:
This is still an approximation, and it will give wrong results when moving big distances, especially near the poles and when crossing the 180th meridian.