指定一個經緯度,給定一個範圍值(單位:公里),查出在經緯度周圍這個範圍內的數據。
經度:113.914619
緯度:22.50128
範圍:2km
longitude爲數據表經度字段
latitude爲數據表緯度字段
SQL在mysql下測試經過,其餘數據庫可能須要修改
SQL語句以下:select * from location where sqrt( mysql
( git
((113.914619-longitude)*PI()*12656*cos(((22.50128+latitude)/2)*PI()/180)/180) sql
* 數據庫
((113.914619-longitude)*PI()*12656*cos (((22.50128+latitude)/2)*PI()/180)/180) 測試
) spa
+ it
( io
((22.50128-latitude)*PI()*12656/180) class
* select
((22.50128-latitude)*PI()*12656/180)
)
)<2