1. 程式人生 > >sql經緯度查詢

sql經緯度查詢

查詢某一座標附近1公里內的資訊

select * from parking
		where pa_examine=1 and pa_yes=1 and sqrt(
		(
		((#pa_longitude#-pa_longitude) * PI () * 12656 * cos
		(((#pa_latitude# + pa_latitude)/2) * PI
		()/180)/180)
		*
		((#pa_longitude#-pa_longitude) * PI () * 12656 * cos (((#pa_latitude#
		+ pa_latitude)/2) * PI
		()/180)/180)
		)
		+
		(
		((#pa_latitude# -pa_latitude)* PI
		()* 12656/180)
		*
		((#pa_latitude# -pa_latitude)* PI ()* 12656/180)
		)
		)<=1 


查詢距離某一左邊最近的20個資訊

order by ACOS(SIN((#ho_longitude# * 3.1415) / 180 )
		*SIN((ho_latitude * 3.1415) / 180 ) +COS((#ho_longitude# * 3.1415) / 180
		) * COS((ho_latitude * 3.1415) / 180 ) *COS((#ho_latitude# * 3.1415) /
		180 - (ho_longitude * 3.1415) / 180 ) ) * 6380 asc limit 20