我們有一個包含地點及其緯度和經度的表格。使用經度和緯度在SQL Server 2008中的兩個位置之間的返回距離
我們試圖在SQL Server 2008中創建一個函數,以特定的經度和緯度爲中心點列出未來25公里內的地點。
我是遊蕩,如果這是啓動和測試我們的功能,並得到一箇中心點之間的當前距離(當前位置)和目標位置(@緯度/ @經度)的好方法:
ALTER FUNCTION [dbo].[GetDistanceFromLocation]
(
@myCurrentLatitude float,
@myCurrentLongitude float,
@latitude float,
@longitude float
)
RETURNS int
AS
BEGIN
DECLARE @radiusOfTheEarth int
SET @radiusOfTheEarth = 6371--km
DECLARE @distance int
SELECT @distance = (@radiusOfTheEarth
* acos(cos(radians(@myCurrentLatitude))
* cos(radians(@latitude))
* cos(radians(@longitude) - radians(@myCurrentLongitude)) + sin(radians(@myCurrentLatitude))
* sin(radians(@latitude))))
RETURN @distance
END
這是正確的還是我們錯過了什麼?
什麼是4326?我試圖看到MSDN,但沒有任何有關它的信息。 –
4326是世界大地測量參考系統的空間參考ID。有關更多信息,請參閱http://technet.microsoft.com/en-us/library/bb933811.aspx http://en.wikipedia.org/wiki/SRID和http://en.wikipedia.org/wiki/WGS84 –