SELECT
htx.ID, Longitude, Latitude
,acos(sin(radians(24.80181500042168)) * sin(radians(Latitude )) + cos(radians(24.80181500042168)) * cos(radians(Latitude )) * cos(radians(120.971596999978 - Longitude))) * 6372.8
as rout_distance
, 24.80181500042168 as route_lat
, 120.971596999978 as route_lon
FROM Info htx
WHERE
(Longitude BETWEEN 120.961801499978
AND 120.981392499978) and(Latitude BETWEEN 24.7928168004217
AND 24.8108132004217) order by rout_distance , Type desc , Name
說明1: 24.80181500042168 是我要查詢的中心點 LAT, 120.971596999978 是我的中心點 LON.說明2: 原本用來取距離是用 between 取, 但這有一個問題, 就是在正方向角角的, 其實會超過預設的距離.
來源:http://maxtellyou.blogspot.tw/2012/09/sql2.html
沒有留言:
張貼留言