CREATE FUNCTION [dbo].[fnGetDistanceGaode]
(@LatBegin REAL, @LngBegin REAL, @LatEnd REAL, @LngEnd REAL) RETURNS FLOAT
AS
BEGIN
--距离(米)
DECLARE @Distance FLOAT
DECLARE @d REAL SET @d = 0.01745329251994329
SET @LatBegin = @LatBegin * @d
SET @LngBegin = @LngBegin * @d
SET @LatEnd = @LatEnd * @d
SET @LngEnd = @LngEnd * @d
DECLARE @d2 REAL SET @d2 = SIN(@LatBegin)
DECLARE @d3 REAL SET @d3 = SIN(@LngBegin)
DECLARE @d4 REAL SET @d4 = SIN(@LatEnd)
DECLARE @d5 REAL SET @d5 = SIN(@LngEnd)
DECLARE @d6 REAL SET @d6 = COS(@LatBegin)
DECLARE @d7 REAL SET @d7 = COS(@LngBegin)
DECLARE @d8 REAL SET @d8 = COS(@LatEnd)
DECLARE @d9 REAL SET @d9 = COS(@LngEnd)
SET @Distance = SQRT(POWER((@d6*@d7 - @d8*@d9),2) + POWER(@d3*@d6 - @d5*@d8, 2) + POWER((@d2 - @d4), 2))
RETURN ASIN(@Distance / 2) * 12742001.579854401
END
GO