2013-04-18 20 views
0

我得到移動我當前的地理位置(long./lat。),我將這個地理位置在線存儲在SQL Server 2008數據庫。我如何檢查我沒有這個位置(可能在100米的半徑內)?檢查地理位置已經在我的數據庫

+0

我回答了一個類似的問題[這裏] [1]。看看你是否可以使用它。 [1]:http://stackoverflow.com/questions/15628794/radius-search-by-latitude-longitude/15640498#15640498 –

回答

0

我能想到的最簡單的方法做,這是一個WHERE NOT EXISTS(100米以內的位置)

下面是該實施示例:

--A table with some coordinates. 
create table #myexistinglocations 
(id int identity(1,1) primary key clustered not null 
,location geography not null 
,shortdescription varchar(30) null 
) 
insert into #myexistinglocations 
values(geography::Point(40.750508,-73.993735,4326),'Madison Square Garden') 
,(geography::Point(40.705524,-74.01351,4326),'Charging Bull') 
; 

WITH myNewLocations(l,sd) --Represents the new stuff I want to put in. 
as 
(
SELECT geography::Point(40.70585,-74.013486,4326),'Wall Street bull!' 
UNION ALL SELECT geography::Point(40.713728,-73.990173,4326),'East Broadway!' 
) 
SELECT 
* 
FROM myNewLocations as a 
WHERE NOT EXISTS (SELECT 1 FROM #myexistinglocations as b WHERE b.location.STDistance (a.l) <= 100) 

的最後一行是什麼對你的問題至關重要。只有「東百老匯!」將自「華爾街牛市」起迴歸!太靠近現有位置。

相關問題