create or replace function getDistance(lon1 in number, lat1 in number,lon2 in number,lat2 in number) return number as
dd number := 0;
radius number := 6378140.0;
PI number := 3.1415926535897932384626433832795028842;
begin
dd := (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;
return dd;
end getDistance;
dd number := 0;
radius number := 6378140.0;
PI number := 3.1415926535897932384626433832795028842;
begin
dd := (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;
return dd;
end getDistance;
本文介绍了一个用于计算地球上两点间地理距离的PL/SQL函数getDistance。该函数接收四组经纬度坐标作为输入参数,并利用球面三角公式计算出两点之间的直线距离。
7161

被折叠的 条评论
为什么被折叠?



