2013-11-20 79 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 

我們還在測試它,但希望它的工作!