坐标 多种数据库计算GPS经纬度坐标距离

mysql计算GPS经纬度距离

DELIMITER $$
CREATEDEFINER=`root`@`localhost` FUNCTION`getDistance`(
lon1 float(10,7)
,lat1 float(10,7)
,lon2 float(10,7)
,lat2 float(10,7)
) RETURNSdouble
begin
declared double;
declareradius int;
setradius = 6378140; #假设地球为正球形,直径为6378140米
setd = (2*ATAN2(SQRT(SIN((lat1-lat2)*PI()/180/2)
*SIN((lat1-lat2)*PI()/180/2)+
COS(lat2*PI()/180)*COS(lat1*PI()/180)
*SIN((lon1-lon2)*PI()/180/2)
*SIN((lon1-lon2)*PI()/180/2)),
SQRT(1-SIN((lat1-lat2)*PI()/180/2)
*SIN((lat1-lat2)*PI()/180/2)
+COS(lat2*PI()/180)*COS(lat1*PI()/180)
*SIN((lon1-lon2)*PI()/180/2)
*SIN((lon1-lon2)*PI()/180/2))))*radius;
returnd;
end

sqlServer计算GPS经纬度距离

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[getDistance](@lng1 FLOAT,@lat1 FLOAT,@lng2 FLOAT,@lat2 FLOAT)
RETURNS FLOAT
AS
BEGIN
        DECLARE @Distance      FLOAT
        DECLARE @EARTH_RADIUS  FLOAT
        SET @EARTH_RADIUS = 6378140
        DECLARE @RadLatBegin  FLOAT,
                @RadLatEnd    FLOAT,
                @RadLatDiff   FLOAT,
                @RadLngDiff   FLOAT
        SET @RadLatBegin = @lat1 *PI()/ 180.0
        SET @RadLatEnd = @lat2 *PI()/ 180.0
        SET @RadLatDiff = @RadLatBegin - @RadLatEnd
        SET @RadLngDiff = @lng1 *PI()/ 180.0 - @lng2 *PI()/ 180.0
        SET @Distance = 2 *ASIN(
                SQRT(
                    POWER(SIN(@RadLatDiff / 2), 2)+COS(@RadLatBegin)*COS(@RadLatEnd)
                    *POWER(SIN(@RadLngDiff / 2), 2)
                )
            )
        SET @Distance =ROUND(@Distance * @EARTH_RADIUS,1)
        --SET @Distance = Round(@Distance * 10000) / 10000
        RETURN @Distance
END


Oracle计算GPS经纬度距离

create or replace FUNCTION GET_DISTANCE
(
  LNG1 IN NUMBER,
  LAT1 IN NUMBER,
  LNG2 IN NUMBER,
  LAT2 IN NUMBER
) RETURN NUMBER IS
  DISTANCE NUMBER:=0;
  PI NUMBER:=3.141592625;
  EARTH_RADIUS NUMBER :=6378140;
  RADLATBEGIN NUMBER :=LAT1*PI/180.0;
  RADLATEND NUMBER :=LAT2*PI/180.0;
  RADLATDIFF NUMBER :=RADLATBEGIN-RADLATEND;
  RADLNGDIFF NUMBER :=LNG1*PI/180.0-LNG2*PI/180.0;
BEGIN
  DISTANCE:=2*ASIN(SQRT(POWER(SIN(RADLATDIFF/2),2)+COS(RADLATBEGIN)*COS(RADLATEND)*POWER(SIN(RADLNGDIFF/2),2)));
  DISTANCE:=ROUND(DISTANCE*EARTH_RADIUS,1);
  RETURN DISTANCE;
END GET_DISTANCE;


PHP计算GPS经纬度坐标


你可能感兴趣的:(数据库与缓存,坐标)