仅供参考 - 目前,我正在使用 SQL Server 2008 空间数据类型、空间函数和一些我在网上找到的 T-SQL 函数。
ALTER FUNCTION dbo.GeographyBearing (
@Point1 geography,
@Point2 geography )
RETURNS FLOAT
AS
BEGIN
DECLARE @Bearing DECIMAL(18,15)
DECLARE @Lat1 FLOAT = RADIANS(@Point1.Lat)
DECLARE @Lat2 FLOAT = RADIANS(@Point2.Lat)
DECLARE @dLon FLOAT = RADIANS(@Point2.Long - @Point1.Long)
IF (@Point1.STEquals(@Point2) = 1)
SET @Bearing = NULL
ELSE
SET @Bearing = ATN2(
SIN(@dLon)*COS(@Lat2),
(COS(@Lat1)*SIN(@Lat2)) - (SIN(@Lat1)*COS(@Lat2)*COS(@dLon))
)
SET @Bearing = (DEGREES(@Bearing) + 360) % 360
RETURN ISNULL(@Bearing,0);
END
GO
DECLARE @Vienna geography = geography::Point(16.37, 48.21, 4326)
DECLARE @Moscow geography = geography::Point(37.60, 55.75, 4326)
SELECT dbo.GeographyBearing(@Vienna,@Moscow)