http://hanhead.tistory.com/entry/Calculate-Distance-and-Radius-in-ASP

위도와 경도를 이용하여 거리를 구하는 vbscript 함수입니다.











'**************************************
    ' Name: Calculate Distance and Radius in
    '     ASP
    ' Description:This function calculates t
    '     he distance between two locations by usi
    '     ng latitude and longitude from ZIP code,
    '     postal code or postcode. The result is a
    '     vailable in miles, kilometers or nautica
    '     l miles based on great circle distance c
    '     alculation.
    ' By: ZipCodeWorld
    '
    'This code is copyrighted and has
    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=9307&lngWId=4
    'for details.
    '**************************************
    
    <%
    ':::::::::::::::::::::::::::::::::::::::
    '     ::::::::::::::::::::::::::::::::::::::::
    '     
    '::: :::
    '::: This routine calculates the distanc
    '     e between two points (given the :::
    '::: latitude/longitude of those points)
    '     . It is being used to calculate :::
    '::: the distance between two ZIP Codes 
    '     or Postal Codes using our:::
    '::: ZIPCodeWorld(TM) and PostalCodeWorl
    '     d(TM) products. :::
    '::: :::
    '::: Definitions::::
    ':::South latitudes are negative, east l
    '     ongitudes are positive:::
    '::: :::
    '::: Passed to function::::
    ':::lat1, lon1 = Latitude and Longitude 
    '     of point 1 (in decimal degrees) :::
    ':::lat2, lon2 = Latitude and Longitude 
    '     of point 2 (in decimal degrees) :::
    ':::unit = the unit you desire for resul
    '     ts:::
    ':::where: 'M' is statute miles:::
    '::: 'K' is kilometers (default):::
    '::: 'N' is nautical miles :::
    '::: :::
    '::: United States ZIP Code/ Canadian Po
    '     stal Code databases with latitude:::
    '::: & longitude are available at http:/
    '     /www.zipcodeworld.com:::
    '::: :::
    '::: For enquiries, please contact sales
    '     @zipcodeworld.com:::
    '::: :::
    '::: Official Web site: http://www.zipco
    '     deworld.com :::
    '::: :::
    '::: Hexa Software Development Center ?
    '     All Rights Reserved 2004:::
    '::: :::
    ':::::::::::::::::::::::::::::::::::::::
    '     ::::::::::::::::::::::::::::::::::::::::
    '     
    Const pi = 3.14159265358979323846
    function distance(lat1, lon1, lat2, lon2, unit)
    Dim theta, dist
    theta = lon1 - lon2
    dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta))
    dist = acos(dist)
    dist = rad2deg(dist)
    distance = dist * 60 * 1.1515
    Select Case ucase(unit)
    Case "K"
    distance = distance * 1.609344
    Case "N"
    distance = distance * 0.8684
    End Select
    End function 
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    '::: This function get the arccos functi
    '     on from arctan function:::
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    function acos(rad)
    if Abs(rad) <> 1 Then
    acos = pi/2 - Atn(rad / Sqr(1 - rad * rad))
    ElseIf rad = -1 Then
    acos = pi
    End if
    End function
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    '::: This function converts decimal degr
    '     ees to radians :::
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    function deg2rad(Deg)
    	deg2rad = cdbl(Deg * pi / 180)
    End function
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    '::: This function converts radians to d
    '     ecimal degrees :::
    ':::::::::::::::::::::::::::::::::::::::
    '     :::::::::::::::::::::::::::::::
    function rad2deg(Rad)
    	rad2deg = cdbl(Rad * 180 / pi)
    End function
    response.write distance(32.9697, -96.80322, 29.46786, -98.53506, "M") & " Miles<BR>"
    response.write distance(32.9697, -96.80322, 29.46786, -98.53506, "K") & " Kilometers<BR>"
    response.write distance(32.9697, -96.80322, 29.46786, -98.53506, "N") & " Nautical Miles<BR>"
    %>

+ Recent posts