2013-11-20 80 views
0

我们在Sql server数据库中有Locations数据。每个Location定义4个点(bounding rectangle)。四点是Bottom Latitude, Top Latitude, Left Longitude, Right Longitude。如果谷歌地图属于边界矩形的任何区域,则会为该位置绘制一个标记。在Google地图上搜索矩形

我们在数据库中有一些其他位置,我们只存储了其中的Lat Lng,我们正在使用下面的查询搜索它们,它的工作原理!

SELECT * 
FROM  SomeOtherLocationsTable 
WHERE LocationLatitude >= @bottomlat AND 
     LocationLatitude <= @toplat AND 
     LocationLongitue >= @leftlang AND 
     LocationLongitue <= @rightlng 

我们如何搜索具有为其定义的四个点的位置?

+0

让我找到一个解决方案,然后我会证明这个问题不是“太宽泛”。 –

回答

1

使用STIntersects

相反,你应该存储geometries(那么你可以使用点和多边形相同的查询)

0

一些R & D后的数字,我们可以在下面找到解决方案,并为我们工作(我们需要的只有美国地区)的功能:

SELECT * 
FROM  LocationsTable 
WHERE  
    NorthEastLongitudeRectangle < @SouthWestLongitudeRectangle OR 
    SouthWestLongitudeRectangle > @NorthEastLongitudeRectangle OR 
    NorthEastLatitudeRectangle < @SouthWestLatitudeRectangle OR 
    SouthWestLatitudeRectangle1 > @NorthEastLatitudeRectangle 

我们还在测试它,但希望它的工作!