在纬度/经度矩形内返回结果

时间:2013-07-21 15:03:33

标签: sql sql-server sql-server-2008 google-maps

以下是我的表格示例:

CREATE TABLE [dbo].[Addresses] (
[Id] int NOT NULL IDENTITY(1,1) ,
[Latitude] float(53) NULL,
[Longitude] float(53) NULL
)

从我们的应用程序中,我以边界框格式返回2组纬度和逻辑点:

{"upperright":[32.91052662576775,-79.5290690551758],"lowerleft":[32.6420709033305,-80.33313094482423]}

因此,根据边界框结果中的内容,我需要将该信息传递给SQL查询以查找该矩形内的所有地址。

2 个答案:

答案 0 :(得分:0)

获取重复的纬度和经度

WITH Dup_LatLong AS
(
SELECT row_number() OVER (PARTITION BY
LATITUDE, LONGITUDE ORDER BY Rpropid1) AS RowNumber, UniqueValue, convert(Varchar(50),LATITUDE)+convert(Varchar(50),LONGITUDE) Check_Cond
FROM YourTable)
Select UniqueValue,LATITUDE, LONGITUDE, convert(Varchar(50),LATITUDE)+convert(Varchar(50),LONGITUDE)
from YourTable
where convert(Varchar(50),LATITUDE)+convert(Varchar(50),LONGITUDE) in (Select Check_Cond from Dup_LatLong where RowNumber > 1)
order by 7

答案 1 :(得分:-1)

这对我有用:

Select * from Addresses
Where Addresses.Longitude between -80.33313094482423 and  -79.5290690551758
And Addresses.Latitude between 32.6420709033305 and 32.91052662576775