sql server2008根據經緯度計算兩點之間的距離

來源:互聯網
上載者:User

標籤:

--通過經緯度計算兩點之間的距離 create  FUNCTION [dbo].[fnGetDistanceNew]   --LatBegin 開始經度 --LngBegin 開始維度 --29.490295,106.486654,29.615467, 106.581515 (@LatBegin1 varchar(128), @LngBegin1 varchar(128),@location varchar(128))      Returns real       ASBEGIN       --轉換location欄位,防止欄位太長.影響SQL美觀       declare  @LatBegin REAL       declare  @LngBegin REAL       declare  @LatEnd REAL       declare  @LngEnd REAL       set @LatBegin=Convert(real,@LatBegin1)       set @LngBegin=Convert(real,@LngBegin1)       set @LatEnd=Convert(real,SUBSTRING(@location,0,charindex(‘&‘,@location)))       set @LngEnd=Convert(real,SUBSTRING(@location,charindex(‘&‘,@location)+1,LEN(@location)))             --距離(千米)       DECLARE @Distance      REAL       DECLARE @EARTH_RADIUS  REAL       SET @EARTH_RADIUS = 6371.004       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) / 10000,5)       RETURN @Distance       END

 

sql server2008根據經緯度計算兩點之間的距離

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.