我得到移动设备当前的地理位置(long./lat。),我将这个地理位置在线存储在sql server 2008数据库中。我如何检查我还没有这个位置(可能在半径100米范围内)?
答案 0 :(得分:0)
我能想到的最简单的方法是,这是一个不存在的地方(位置在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)
最后一行是您的问题所必需的。只有“东百老汇!”自“华尔街牛市”以来将被退回!离现有地点太近了。