本文介紹了使用 SQL 查詢查找最近的緯度/經(jīng)度的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有緯度和經(jīng)度,我想從數(shù)據(jù)庫中提取記錄,該記錄具有距離最近的緯度和經(jīng)度,如果該距離超過指定的距離,則不要檢索它.
I have latitude and longitude and I want to pull the record from the database, which has nearest latitude and longitude by the distance, if that distance gets longer than specified one, then don't retrieve it.
表結(jié)構(gòu):
id
latitude
longitude
place name
city
country
state
zip
sealevel
推薦答案
SELECT latitude, longitude, SQRT(
POW(69.1 * (latitude - [startlat]), 2) +
POW(69.1 * ([startlng] - longitude) * COS(latitude / 57.3), 2)) AS distance
FROM TableName HAVING distance < 25 ORDER BY distance;
其中 [starlat] 和 [startlng] 是開始測量距離的位置.
where [starlat] and [startlng] is the position where to start measuring the distance.
這篇關于使用 SQL 查詢查找最近的緯度/經(jīng)度的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!