[英]MySQL: get record within polygon
我在數據庫中有一個表,其中包含緯度和經度屬性
CREATE TABLE `companies` (
`ID` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`latitude` decimal(12,8) NOT NULL,
`longitude` decimal(12,8) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `companies` (`ID`, `title`, `latitude`, `longitude`) VALUES
(NULL, 'John and SOns', '25.29064622', '55.368462502'),
(NULL, 'Evas', '25.28862850', '55.40107816');
在谷歌地圖上我有一個折線功能,用戶可以繪制折線,這樣我們就可以顯示該多邊形內的所有公司。
這是地圖圖片
我如何查詢從數據庫中獲取繪制多邊形內的所有記錄?
如果您將查詢編寫為:
select ID,title from companies where st_within(point(companies.longitude,companies.latitude), ST_GeomFromText('Polygon((75.80278873443604 26.863847231536703, 75.79540729522705 26.85136594544373, 75.81798076629639 26.851595674802315,75.80278873443604 26.863847231536703))'));
那應該是有用的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.