Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Can someone break down this zipcode locator

1. ## 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
' 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
'_________________________________
' 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:

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

• 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
•