首页 > 代码库 > sql中经度维度计算距离
sql中经度维度计算距离
------------------------------------------创建一个方法--------------------------------------------------------------------
--@LatBegin 纬度A(33.8703596)----@LngBegin 经度A(-117.9242966)----@LatEnd 纬度B(34.0392283)----@LngEnd 经度B(-117.8367681)--CREATE FUNCTION [dbo].[fnGetDistance](@LatBegin REAL, @LngBegin REAL, @LatEnd REAL, @LngEnd REAL) RETURNS FLOAT AS BEGIN --距离(千米) DECLARE @Distance REAL --距离(英里)-- DECLARE @Edistance REAL DECLARE @EARTH_RADIUS REAL DECLARE @MI REAL SET @EARTH_RADIUS = 6378.137 --地球半径(千米)-- Set @MI=0.6213712 --1千米(km)=0.6213712英里(mi) DECLARE @RadLatBegin REAL,@RadLatEnd REAL,@RadLatDiff REAL,@RadLngDiff REAL SET @RadLatBegin = @LatBegin *PI()/180.0 SET @RadLatEnd = @LatEnd *PI()/180.0 SET @RadLatDiff = @RadLatBegin - @RadLatEnd SET @RadLngDiff = @LngBegin *PI()/180.0 - @LngEnd *PI()/180.0 SET @Distance = 2 *ASIN(SQRT(POWER(SIN(@RadLatDiff/2), 2)+COS(@RadLatBegin)*COS(@RadLatEnd)*POWER(SIN(@RadLngDiff/2), 2))) SET @Distance = @Distance * @EARTH_RADIUS SET @Distance = Round(@Distance * 10000,1) / 10000 --千米-- SET @Edistance= @Distance * @MI --英里-- RETURN @Edistance END
------------------------------------------删除方法--------------------------------------------------------------------
drop function dbo.fnGetDistance
------------------------------------------调用方法--------------------------------------------------------------------
select dbo.fnGetDistance(33.8703596,-117.9242966,34.0392283,-117.8367681)
sql中经度维度计算距离
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。