根据经纬度计算两地距离的sql函数


--获得弧度的函数
CREATE OR REPLACE FUNCTION Radian(d number) RETURN NUMBER
is
PI number :=3.141592625;

begin
return  d* PI/180.0;
end ;

 

--根据经纬度计算距离的函数
CREATE OR REPLACE FUNCTION GetDistance(lat1 number,
                                       lng1 number,
                                       lat2 number,
                                       lng2 number) RETURN NUMBER is
  earth_padius number := 6378.137;
  radLat1      number := Radian(lat1);
  radLat2      number := Radian(lat2);
  a            number := radLat1 - radLat2;
  b            number := Radian(lng1) - Radian(lng2);
  s            number := 0;
begin
  s := 2 *
       Asin(Sqrt(power(sin(a / 2), 2) +
                 cos(radLat1) * cos(radLat2) * power(sin(b / 2), 2)));
  s := s * earth_padius;
  s := Round(s * 10) / 10;
  return s;

end;

 

你可能感兴趣的:(JAVA学习资料)