-
GPS좌표 두지점간 거리계산 소스 - ASP/MSSQL/JS웹프로그래밍/ASP 2011. 5. 30. 17:41반응형
인터넷에서 찾은 php소스를 asp에서 사용할수 있도록 변환.
[ASP]
<% function asin(x) asin = atn(x / sqr(1 - x ^ 2)) end function function acos(x) acos = M_PI_2 - asin(x) end function function getMeter(lat1, lng1, lat2, lng2) if (lat1 = lat2) and (lng1 = lng2) then getMeter = 0 else pi = 4 * atn(1) e10 = lat1 * pi / 180 e11 = lng1 * pi / 180 e12 = lat2 * pi / 180 e13 = lng2 * pi / 180 c16 = 6356752.314140910 c15 = 6378137.000000000 c17 = 0.0033528107 f15 = c17 + c17 * c17 f16 = f15 / 2 f17 = c17 * c17 / 2 f18 = c17 * c17 / 8 f19 = c17 * c17 / 16 c18 = e13 - e11 c20 = (1 - c17) * tan(e10) c21 = atn(c20) c22 = sin(c21) c23 = cos(c21) c24 = (1 - c17) * tan(e12) c25 = atn(c24) c26 = sin(c25) c27 = cos(c25) c29 = c18 c31 = (c27 * sin(c29) * c27 * sin(c29)) + (c23 * c26 - c22 * c27 * cos(c29)) * (c23 * c26 - c22 * c27 * cos(c29)) c33 = (c22 * c26) + (c23 * c27 * cos(c29)) c35 = sqr(c31) / c33 c36 = atn(c35) c38 = 0 if c31 = 0 then c38 = 0 else c38 = c23 * c27 * sin(c29) / sqr(c31) end if c40 = 0 if (cos(asin(c38)) * cos(asin(c38))) = 0 then c40 = 0 else c40 = c33 - 2 * c22 * c26 / (cos(asin(c38)) * cos(asin(c38))) end if c41 = cos(asin(c38)) * cos(asin(c38)) * (c15 * c15 - c16 * c16) / (c16 * c16) c43 = 1 + c41 / 16384 * (4096 + c41 * (-768 + c41 * (320 - 175 * c41))) c45 = c41 / 1024 * (256 + c41 * (-128 + c41 * (74 - 47 * c41))) c47 = c45 * sqr(c31) * (c40 + c45 / 4 * (c33 * (-1 + 2 * c40 * c40) - c45 / 6 * c40 * (-3 + 4 * c31) * (-3 + 4 * c40 * c40))) c50 = c17 / 16 * cos(asin(c38)) * cos(asin(c38)) * (4 + c17 * (4 - 3 * cos(asin(c38)) * cos(asin(c38)))) c52 = c18 + (1 - c50) * c17 * c38 * (acos(c33) + c50 * sin(acos(c33)) * (c40 + c50 * c33 * (-1 + 2 * c40 * c40))) c54 = c16 * c43 * (atn(c35) - c47) getMeter = FormatNumber((c54/1000),1) '키로미터 end if end function %>
[사용예]
'전주역 : 35.849773, 127.161796
'전주시청 : 35.824112, 127.148078
response.write(getMeter(35.849773, 127.161796, 35.824112, 127.148078) &"km")[결과]
3.1km
[MSSQL]
select ( 6371 /* 6371->키로미터 단위, 3959->마일단위 */ * acos( cos( radians(lat1) ) * cos( radians(lat2)) * cos( radians(lng2) - radians(lng1) ) + sin( radians(lat1) ) * sin( radians(lat2) ) ) ) AS distance from 테이블
[Java Script]
function getmeter(lat1, lon1, lat2, lon2) { delta_lon = deg2rad(lon2) - deg2rad(lon1); distance = Math.acos(Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(delta_lon)) * 3963.189; //마일 gap = parseInt(distance * 1609.344); return gap; } function deg2rad(val) { var pi = Math.PI; var de_ra = ((eval(val))*(pi/180)); return de_ra; }
반응형'웹프로그래밍 > ASP' 카테고리의 다른 글
ASP로 XML페이지 만들기 (1) 2009.06.04 난수발생-ASP (0) 2007.12.30 웹페이지 소스 긁어오기 (0) 2007.12.19