My code is below... works well, here's the results:
http://www.daikinac.com/commercial/locator_submit_test.aspBut, I need help ORDERING the zip codes by DISTANCE... and I'm really struggling. The problem is that "Distance" is declared AFTER the SQL for the recordset. I also need to round the mileage up, to only two decimal points.
The code so far is below, and ideas would be much appreciated.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
<!--#include file="DistanceAssistant.in
c"-->
<!--#include file="RadiusAssistant.inc"
-->
Dim _
ZIPCode, _
Miles, _
_
Latitude, _
Longitude, _
_
ZIPExists, _
_
DatabaseConnection, _
DatabaseQuery
ZIPCode = "10001"
Miles = 5
Latitude = 0
Longitude = 0
ZIPExists = False
DatabaseConnection = "xxxxxxxx"
Dim dbConn: Set dbConn = CreateObject("ADODB.Connec
tion")
dbConn.Open DatabaseConnection
DatabaseQuery = "SELECT Latitude, Longitude FROM PostalCodes WHERE PostalCode = '" & ZIPCode & "'"
Dim rsZIPCodes: Set rsZIPCodes = CreateObject("ADODB.Record
set")
rsZIPCodes.Open DatabaseQuery, dbConn
If rsZIPCodes.EOF Then
'ZIP Code does not exist - report to user...
Else
'ZIP Code does exist...get lat/long
Latitude = rsZIPCodes("Latitude")
Longitude = rsZIPCodes("Longitude")
ZIPExists = True
End If
rsZIPCodes.Close
Set rsZIPCodes = Nothing
If ZIPExists Then
Dim zcdRadius: Set zcdRadius = CreateObject("ZIPCodeDownl
oad.Radius
Assistant"
)
zcdRadius.Calculate Latitude, Longitude, Miles
Dim _
MaxLatitude, _
MaxLongitude, _
MinLatitude, _
MinLongitude
MaxLongitude = zcdRadius.MaxLongitude
MinLongitude = zcdRadius.MinLongitude
MaxLatitude = zcdRadius.MaxLatitude
MinLatitude = zcdRadius.MinLatitude
Set zcdRadius = Nothing
DatabaseQuery = "" _
& " SELECT * FROM PostalCodes inner join dna_dealers on postalcodes.postalcode like dna_dealers.postalcode WHERE" _
& " Latitude >= " & MinLatitude _
& " AND Latitude <=" & MaxLatitude _
& " AND Longitude >= " & MinLongitude _
& " AND Longitude <= " & MaxLongitude _
& " AND CityType = 'D'"
Dim zcdDistance: Set zcdDistance = CreateObject("ZIPCodeDownl
oad.Distan
ceAssistan
t")
Set rsZIPCodes = CreateObject("ADODB.Record
set")
rsZIPCodes.Open DatabaseQuery, dbConn
While Not rsZIPCodes.EOF
Dim _
Latitude2, _
Longitude2, _
Distance
Latitude2 = rsZIPCodes("Latitude")
Longitude2 = rsZIPCodes("Longitude")
Distance = zcdDistance.Distance(Latit
ude, Longitude, Latitude2, Longitude2)
If Distance <= Miles Then
'this ZIP Code is within Miles of ZIPCode
'display appropriate information to the user...
Dim strCity : strCity = rsZIPCodes("City")
Dim strAccount: strAccount = rsZIPCodes("Account")
Response.Write(strCity & " - " & strAccount & " - " & Distance & "<BR>")
End If
rsZIPCodes.MoveNext
Wend
rsZIPCodes.Close
Set rsZIPCodes = Nothing
End If
dbConn.Close
Set dbConn = Nothing
%>