I'm using VB6 with ADODB on an Access 2000 DB.
I have a table full of zip codes mapped to their Longitudes and Latitudes.
It's easy to feed it a Zip and get the Lon and Lat.
But I also want to be able to feed it a Lon and Lat to find the nearest Zip Code.
Now I could do it this way:
That could return a range of zips/lon's/lat's that I'd have to filter to find the one closest to the original coordinates.Code:sSQL = "SELECT * FROM tblZip WHERE LONGITUDE <= " & dblLon + 0.0005 & _ " AND LONGITUDE >= " & dblLon - 0.0005 & _ " AND LATITUDE <= " & dblLat + 0.0005 & _ " AND LATITUDE >= " & dblLat - 0.0005
What I'd like to know is, is there a way to write the sSQL so that it only returns the LONGITUDE and LATITUDE that are closest to dblLon and dblLat?
P.S. I haven't been here for quite a while, how are the <vbcode> tags done now?




Reply With Quote