I currently have a MySQL table that is structured as follows:
id name lon lat
----- ----- ----------- -----------
1
Spherical Law of Cosines Formula
(37 and -122 are the latitude and longitude of your radius center)
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) )
* cos( radians( long ) - radians(-122) ) + sin( radians(37) ) * sin(radians(lat)) ) ) AS distance
FROM myTable
HAVING distance < 50
ORDER BY distance
Features
Haversine Formula
SELECT id, 3956 * 2 * ASIN(SQRT(POWER(SIN((37 - abs(lat)) * pi()/180 / 2), 2)
+ COS(37 * pi()/180 ) * COS(abs(lat) * pi()/180)
* POWER(SIN((-122 - long) * pi()/180 / 2), 2) )) as distance
FROM myTable
HAVING distance < 50
ORDER BY distance
Features
Note that 3959 is the Earth radius in miles. Earth radius in km: 6371
You can find more information here