Hope this helps you
Code:
SELECT *,
truncate((degrees(acos(sin(radians(latitude)) * sin( radians(" . $locale['latitude'] . "))
+ cos(radians(latitude)) * cos( radians(" . $locale['latitude'] . "))
* cos( radians(longitude - " . $locale['longitude'] . ") ) ) )
* 69.09),1) as distance_miles,
DEGREES(
ACOS(
(
SIN(RADIANS(" . $locale['latitude'] . "))
*
SIN(RADIANS(latitude))
)
+
(
COS(RADIANS(" . $locale['latitude'] . "))
*
COS(RADIANS(latitude))
*
COS(RADIANS(" . $locale['longitude'] . " - longitude))
)
)
*
60 * 1.1515 * 1.61
) AS distance_km
FROM locations
ORDER BY `distance` ASC LIMIT 10