我有一个带有Geography类型的sql表列:
create table dbo.Events ( Id int identity not null constraint PK_Events_Id primary key clustered (Id),Localization geography not null );
我怎样才能获得半径为40公里的所有活动?这可能吗?
谢谢,
米格尔
解决方法
假设您有要搜索的点的纬度和经度:
DECLARE @Origin GEOGRAPHY,-- distance defined in meters @Distance INTEGER = 40000; -- center point SET @Origin = GEOGRAPHY::STGeomFromText('POINT(-122.084039 37.42227)',4326); -- return all rows from events in 40km radius SELECT * FROM dbo.Events WHERE @Origin.STDistance(Localizaton) <= @Distance;