Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can someone break down this zipcode locator

    I have the following code. I believe it is supposed to find zipcodes which are within a certain radius of the given zipcode. Could someone break it down step by step so I can adapt it to my application?

    Dim HighLatitude
    Dim LowLatitude
    Dim LowLongitude
    Dim HighLongitude

    Function GetDistance(Lat1, Long1, Lat2, Long2, Unit)
    Dim x
    x = (sin(DegToRads(Lat1)) * sin(DegToRads(Lat2)) + cos(DegToRads(Lat1)) * _
    cos(DegToRads(Lat2)) * cos(abs((DegToRads(long2))-(DegToRads(long1)))))
    ' Get Acos(x)
    x = atn((sqr(1-x^2))/x)
    ' Get distance in kilometers
    GetDistance = 1.852 * 60.0 * ((x/pi)*180)
    ' Convert units if necessary
    Select Case ucase(Unit)
    Case "M"
    GetDistance = GetDistance / 1.609344
    Case "N"
    GetDistance = GetDistance / 1.852
    End Select
    End Function
    '_________________________________
    Sub SetRadius(iRadius, iZip)
    ' THIS VARIABLE SETS THE RADIUS IN MILES

    Dim rs, SQLQ, iStartlat, iStartlong, LatRange, LongRange
    SQLQ = "SELECT LATITUDE, LONGITUDE FROM ZIPCODES WHERE ZIPCODE = '" & iZip & "'"
    Set rs = DBConn.Execute(SQLQ)
    If Not rs.EOF Then
    iStartlat = rs(0)
    iStartlong = rs(1)
    End If
    rs.Close
    Set rs = Nothing
    LatRange = iRadius / ((6076 / 5280) * 60)
    LongRange = iRadius / (((cos(cdbl(iStartLat * 3.141592653589 / 180)) * 6076.) / 5280.) * 60)

    LowLatitude = iStartlat - LatRange
    HighLatitude = iStartlat + LatRange
    LowLongitude = iStartlong - LongRange
    HighLongitude = iStartlong + LongRange
    End Sub
    '_________________________________________________________
    'condition for building SQL String:

    If Request("radius") <> "0" Then
    Call SetRadius(CLng(Request("radius")), Request("zipcode"))
    SQLQ = SQLQ & JoinWord & " Company_Postal_Code IN(SELECT ZIPCODE " & _
    "FROM ZIPCODES WHERE LATITUDE <= " & HighLatitude & " AND LATITUDE >= " & LowLatitude & _
    " AND LONGITUDE >= " & LowLongitude & _
    " AND LONGITUDE <= " & HighLongitude & ")"
    JoinWord = " AND "
    End If

  • #2
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How do you want it broken down? As an interface, as SQL to put into a Stored Proc, ...? How are you planning on using this code, so that I can break this down for you in a usable way.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •