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 に答える