使用SQL地理位置获取某个半径的位置
发布时间:2020-05-28 14:24:54 所属栏目:MsSql 来源:互联网
导读:我有一个带有Geography类型的SQL表列: create table dbo.Events( Id int identity not null constraint PK_Events_Id primary key clustered (Id), Localization geography not null); 我怎样才能获得半径为40公里的所有活动?这可能吗? 谢谢
|
我有一个带有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; (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
