zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    Service Location Protocol SLP
    [http 1.1] M-POST
    安装 wbemcli
    [http 1.1] M-POST w3
    [CODEVS 1288]埃及分数
    [NOIp 2013]货车运输
    [测试题]gentree
    [USACO 07NOV]Cow Relays
    [USACO 13DEC]Vacation Planning(gold)
    [CODEVS 2495]水叮当的舞步
  • 原文地址:https://www.cnblogs.com/ly77461/p/6897697.html
Copyright © 2011-2022 走看看