转自:http://gis.stackexchange.com/a/31629
谷歌的方案
语句:
SELECT
id, `name`,(
6371 * acos (
cos ( radians(60.000000) )
* cos( radians( lat ) )
* cos( radians( lon ) - radians(70.000000) )
+ sin ( radians(60.000000) )
* sin( radians( lat ) )
)
) AS distance
FROM t_demo
HAVING distance < 2
ORDER BY distance
LIMIT 0 , 20;
说明:当前位置纬度:60.000000 经度:70.000000 以公里代替里程搜索,用6371替换3959。
英文原文:
The SQL statement that will find the closest 20 locations that are within a radius of 30 miles to the 78.3232, 65.3234 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 30 miles, orders the whole query by distance, and limits it to 20 results. To search by kilometers instead of miles, replace 3959 with 6371.