Results 1 to 5 of 5

Thread: Searching for 'closest to'

Threaded View

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Searching for 'closest to'

    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:
    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
    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.

    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?
    Last edited by longwolf; Sep 4th, 2008 at 08:49 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width