0

我可以移动我当前的地理位置(long./lat.),我会将此地理位置在线存储在 sql server 2008 数据库中。我如何检查我还没有这个位置(可能在 100 米的半径内)?

4

1 回答 1

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)

最后一行对您的问题至关重要。只有“东百老汇!” 将回归自“华尔街公牛!” 离现有位置太近。

于 2013-04-18T12:52:10.900 回答