获取经纬度之间的距离的SQL函数(转)
时间:2011-04-01 来源:zengjun
--获取经纬度之间的距离(单位:米)
CREATE function dbo.GetDistance(@Lon1 float,@Lat1 float,@Lon2 float,@Lat2 float) returns float
as
begin
declare @ret float;
declare @r float;
declare @A float;
declare @B float;
declare @RA float;
declare @RB float;
declare @RL1 float;
declare @RL2 float;
select @r = 6371138, @A = abs(@Lat1 - @Lat2), @B = abs(@Lon1 - @Lon2), @RA = @A * pi() / 180.0, @RB = @B * pi() / 180.0, @RL1 = @Lat1 * pi() / 180.0, @RL2 = @Lat2 * pi() / 180.0, @ret = cast(2 * @r * asin(sqrt(sin(@RA/2) * sin(@RA/2) + cos(@RL1) * cos(@RL2) * sin(@RB/2) * sin(@RB/2))) as decimal(8,0));
return @ret
end
相关阅读 更多 +