데이터베이스에서 두 지도 좌표점 사이의 거리를 계산하다

2429 단어 데이터베이스
CREATE OR REPLACE FUNCTION DISTANCEBYLNGLAT(LNG1 IN NUMBER,
                                            LAT1 IN NUMBER,
                                            LNG2 IN NUMBER,
                                            LAT2 IN NUMBER) RETURN NUMBER IS
  /********************
   
   
  ********************/
  RADLAT1 NUMBER;
  RADLAT2 NUMBER;
  A       NUMBER;
  B       NUMBER;
  S       NUMBER;
BEGIN
  RADLAT1 := (LAT1 * ACOS(-1)) / 180.0;
  RADLAT2 := (LAT2 * ACOS(-1)) / 180.0;
  A       := RADLAT1 - RADLAT2;
  B       := ((LNG1 * ACOS(-1)) / 180.0) - ((LNG2 * ACOS(-1)) / 180.0);
  S       := 2 *
             ASIN(SQRT(POWER(SIN(A / 2), 2) +
                       COS(RADLAT1) * COS(RADLAT2) * POWER(SIN(B / 2), 2)));
  S       := S * 6378137.0; -- WGS84 ( :M)
  S       := ROUND(S * 10) / 10000;
  RETURN S;
END DISTANCEBYLNGLAT;

자바스크립트 포함
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> </title>
    <script type="text/javascript">  
    function distanceByLnglat(lng1,lat1,lng2,lat2)
{
    var radLat1 = Rad(lat1);
	alert(lat1+"-->"+radLat1);
    var radLat2 = Rad(lat2);
    var a = radLat1 - radLat2;
    var b = Rad(lng1) - Rad(lng2);
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * 6378137.0;//  WGS84 ( :m)
    s = Math.round(s * 10000) / 10000;
alert(s);
// // ( )
// var value= Math.pow(Math.pow(lng1-lng2,2)+Math.pow(lat1-lat2,2),1/2);
// alert(value);
}

function Rad(d)
{
    return d * Math.PI / 180.0;
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div onclick ="distanceByLnglat(116.95400,39.95400,116.95300,39.95300);">
    test me
    </div>
    </form>
</body>
</html>

좋은 웹페이지 즐겨찾기