sql:
SELECT app_station_hdr.*
FROM app_station_hdr
WHERE getDistance(station_Lng, station_Lat, :lon, :lat) < 50000
AND del_flag = 0
LIMIT 10
数据库函数:
CREATE DEFINER=root@% FUNCTION getDistance(
lng1 float(10,7)
,lat1 float(10,7)
,lng2 float(10,7)
,lat2 float(10,7)
) RETURNS double
begin
declare d double;
declare radius int;
set radius = 6378140; #假设地球为正球形,直径为6378140米
set d = (2ATAN2(SQRT(SIN((lat1-lat2)PI()/180/2)
SIN((lat1-lat2)PI()/180/2)+
COS(lat2PI()/180)COS(lat1*PI()/180)
SIN((lng1-lng2)PI()/180/2)
SIN((lng1-lng2)PI()/180/2)),
SQRT(1-SIN((lat1-lat2)*PI()/180/2)
SIN((lat1-lat2)PI()/180/2)
+COS(lat2PI()/180)COS(lat1*PI()/180)
SIN((lng1-lng2)PI()/180/2)
SIN((lng1-lng2)PI()/180/2))))*radius;
return d;
end