Including "radius" in online search

bluesdoggy

Senior member
Aug 8, 2000
206
0
0
I'm in the process of building a database application for use by our sales department. One of the features that has been requested is the abilty to search for all customers within a certain mile radius of a zipcode/city. This is a fairly common feature on most web searches i've seen, so it can't be terribly complex..however i'm not sure how to get the data to make it happen.

I have found the following:

http://www.census.gov/geo/ZCTA/zcta.html

which seems to offer rough approximations in terms of Lat and Lon for zip code areas... however i'm not sure if there's something better i could use in order to also be able to include city searching. Does anyone have any advice / tips on getting this done at a minimal cost? i'd rather have to do some work building interface / populating db from raw info than a "in box" solution that costs any appreciable amount.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
I'd think you should be able to wrangle the Google API to convert addresses to lat/lon, down to seconds of a degree - you should be able to automate that portion (See Geocoding example). You should be able to then find the distance between the two points on demand. Whether you should re-calculate the distance for every call or pre-calc and store in a massive associated DB is beyond me.

Edit: On second thought, you should pre-calc distance. It's a relatively expensive operation, considering you need to a) take into account more than just distance on a 2D plane, and b) you're looking to do that calculation N times for each location, then sort it. If you limit the radius selection to sets instead of arbitrary values, you can optimize a bit more.
 

clamum

Lifer
Feb 13, 2003
26,256
406
126
Do a Google search for "zip code radius search script". You should be able to find something in whatever language you're using. Then do some modification, if needed, to integrate with your setup.