利用谷歌方案
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.
示例:(谷歌)
SELECTid, (3959 * acos (cos ( radians(78.3232) )* cos( radians( lat ) )* cos( radians( lng ) - radians(65.3234) )+ sin ( radians(78.3232) )* sin( radians( lat ) ))) AS distance
FROM markers
HAVING distance < 30
ORDER BY distance
LIMIT 0 , 20;
以上是谷歌说明,下面是用谷歌翻译的哈
根据以上说明,有以下应用实例
其中
3959是地球半径的英里,6371是地球半径的千米,LATITUDE是数据库字段的经度,LONGITUDE是数据库的纬度 ,18.7777是查找的经度,55.3774是查找的纬度即是有(18.7777,55.3774)这个位置点 搜索附近3.7KM的位置数据
SELECTid, (3959 * acos (cos ( radians(18.7777) )* cos( radians( LATITUDE) )* cos( radians( LONGITUDE) - radians(55.3774) )+ sin ( radians(18.7777) )* sin( radians( LATITUDE) ))) AS distance
FROM markers
HAVING distance < 3700
ORDER BY distance
LIMIT 0 , 20;