Else
Radius = 3963.191
'Miles
End If
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("ConnectionString")
Set RS = Server.CreateObject("ADODB.Recordset")
' Search postal codes to get the coordinates of first point
' ---------------------------------------------------------
SQL = "SELECT * FROM [PostalCodes] " & ISO & "'
"
SQL = SQL & "AND PostalCode = '" & PostalCode & "';"
Set RS = Conn.Execute(SQL)
Lat = RS("Latitude")
Lon = RS("Longitude")
'Build
the formula in: calc variable for easy handling in SQL statement
calc = Radius & " *
ACos( Cos(RADIANS(Latitude)) * Cos(RADIANS(" & Lat & ")) *
Cos(RADIANS(" & Lon & ") - RADIANS(Longitude)) + Sin(RADIANS(Latitude)) * Sin(RADIANS(" & Lat & ")) ) "
SQL = "SELECT TOP 100 "
SQL = SQL & "ISO, "
SQL = SQL & "Postalcode, "
SQL = SQL & "Region1, "
SQL = SQL & "Region2, "
SQL = SQL & "Region3, "
SQL = SQL & "Locality, "
SQL = SQL & "Suburb, "
SQL = SQL & "Latitude, "
SQL = SQL & "Longitude, "
SQL = SQL & calc & " AS Distance "
SQL = SQL & "FROM [PostalCodes] "
SQL = SQL & "WHERE (ISO = '" & ISO & "') "
SQL = SQL & "AND " & calc & " <= " & Distance & " "
SQL = SQL & "ORDER BY Distance ;"
Set RS = Conn.Execute(SQL)
DO While Not RS.EOF
Response.Write RS("ISO") & "<br>"
Response.Write RS("PostalCode") & "<br>"
Response.Write RS("Region1") & "<br>"
Response.Write RS("Region2") & "<br>"
Response.Write RS("Region3") & "<br>"
Response.Write RS("Locality") & "<br>"
Response.Write RS("Suburb") & "<br>"
Response.Write FormatNumber(RS("Distance"),1) & "<br>"
RS.MoveNext
Loop
RS.Close
Set RS = nothing
Conn.Close
%>
Reference data |
---|
Administrative divisions |
Countries |
Countries names |
Currencies |
Languages |
Postal codes format |
Time zones |
Formulas & samples |
---|
Distance between points |
Locate points in a radius |
Find postal code of a point |