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经纬度坐标
<?php
functionrad($d){
return$d* 3.1415926535898 / 180.0;
}
functionGetDistance($lat1, $lng1, $lat2, $lng2){
$EARTH_RADIUS= 6378.137;
$radLat1= rad($lat1);
$radLat2= rad($lat2);
$a= $radLat1- $radLat2;
$b= rad($lng1) - rad($lng2);
$s= 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
$s= $s*$EARTH_RADIUS;
$s= round($s* 10000) / 10000;
return$s;
}
echoGetDistance(116.480733,39.98684,117.480733,39.98684);
?>
————————————————
版权声明:本文为CSDN博主「_yuki_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_19707521/article/details/70800933