locLongitude--當前經度, locLatitude--當前緯度;longitude -- 數據庫經度字段名 latitude --數據庫緯度字段名
傳入當前座標,查詢數據庫中距離最近的兩個單位。
select * from t_depot order by ACOS(SIN((#{locLatitude} * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS((#{locLatitude} * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS((#{locLongitude} * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380 asc limit 2;