Here
Distance between two lat,lon points
I found a very simple and nice formula:
d = sqrt(pow(lat2-lat1, 2) + cos(lat1)*pow(lon2-lon1, 2))
which I am using like this:
SELECT name, SQRT(POW(lat-45, 2) + COS(45)*POW(lon-8, 2)) AS distance
FROM shop
ORDER BY distance
and everything worked fine, because I only needed to get an approximate RELATIVE distance.
But then I needed an ABSOLUTE distance, even if approximate... And I started to realize that maybe "d" cannot be converted in meters/miles because e.g. there are 180 degrees of latitude but 360 of longitude, so this almost-Pythagorean theorem is "stretching" the diagonal line in a way that messes up a possible absolute calculation... After a while, I gave up and... Here I am.
How can I convert "d" to an absolute distance in meters/miles?
PS: Yes, I will precalculate all the constants in the SQL query in the final version...