Gossamer Forum
Home : Products : Gossamer Links : Discussions :

ZIP code radius search?

Quote Reply
ZIP code radius search?
Is anyone doing a zip code radius search in their install?

Are there any good databases, modules, or such out there?

I want to be able to restrict searches, and "communities" by zip codes, and need some flexibility in implementation.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] ZIP code radius search? In reply to
Hi pugdog,
I have a plugin I wrote for Zip code radius search. It is simple and works pretty well.
I'll trade you (license for license) for a copy of your Thumb_Images plugin.

Features:
Works with multiple Zip Code databases available on the web.
A Link to a free database of zip codes.
Units: Miles, Kilometers, or Nautical Miles
Max search distance variable.
Sorting ASC or DESC.
Optional Category restricted results and search form.
Optionally add searches to existing Admin search logs.
Automatic updating via pre/post hooks on add/modify

I am working on a "release" version now. It can be seen at supportmusicians.com.
I will have to explain it a little seems I don't have instructions or an sql installer for
the Zip Code database as I have to learn how to do that yet.

As far as testing goes, I have very few links in my db, so try within 53140 and distances of
1 mile, 5, 20, 30, 50, 236 and 250. Then try from the other end (54720) distances 1, 27 and 236.

I was just doing some testing, and just for fun (and my reference, teehee)...
My band "Three Chords & the Truth" (53140) is 236 miles from my brothers
band "Twain Trax" (54720). I don't pick up 54720 until 236 miles (and vis versa). Nice test :-)
I currently get 3 additional results when increasing distance from 50 to 236 (from 53140).
This is correct because all 3 bands additional bands are IN zip code 54720.
If I do a search from 54720, distance 5 miles, I get these 3 bands. Looks good so far.

Interestingly, when I increase to 250 miles (from 53140), I pick up 1 more band "Bear Creek" (54736).
So using my zip of 53140, I theorized that Bear Creek (54736) (dist 250 from me) is 14 miles from
Twain Trax (54720) (dist 236 from me). So, I expected that a search from 54720 distance of 14 miles
would increase results from 3 to 4 (adding Bear Creek - 54736), but they do not get included
until 28 miles. This is an error of 14 miles because 54720 to 54736 is 28 miles when searching
from 54720, yet when searching from 53140, 54736 (250m) appears to be only 14m further than 54720 (236m).
But I don't know if you can do the math that way or not. I know I have done closer searches and
the distances seem accurate within a mile!

Anyways, that testing babble was more for me :-)

Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] ZIP code radius search? In reply to
Hi,

In the interim I found a free set of codes, which seem to be fairly easy, *but* there are still issues.

I don't need super accuracy, since the location is really to the center of a zip code, not to an address, so even older databases are ok for my needs, to a degree.

But, what I see is a *huge* amount of processing overhead, unless databases are pre-generated.

Some of the zipcode databases ship with the 5, 10, 15, 20, 25 and 50 mile searches already pre-generated. So, if you enter your zip, and one of the pre-generated radiuses, your software would do a lookup on that table, pull the record for your zipcode, and get a list of zips that were within that radius. You then split the list, and create an "IN" SQL query for records that match any zipcode in that radius list.

If you had to do the calculations on each and every record, if your database was more than a few dozen records, it would never "fly".

Using the lat/lon tables, for each zip, you could generate those tables, but it would be a huge amount of processing, and you'd only want to ever have to do that once.

That is something actually better done by a C/C++ program, than anything in perl or PHP, or any higher level language.

Without doing a lot of pre-data digestion, which probably wouldn't be very useful, you have to compare the lat/lon of every zip to every other zip, and get a distance table from them. You don't need to do reverse look up, so putting the results into a table like:

zip_1 : zip_2 : distance

where zip_1 is ALWAYS less than zip_2, you would not end up doing a look up of the distance between zip_2 and zip_1

You would then populate the distance tables by extracting and importing the data based on :

distance <= 5 (10, 15, etc)

for distance <= 5, for example, you would get all the references to zip_1 and zip_2 that were less than or equal to 5

So, doing one set of calculations would allow you to generate the data that could be used on multiple searches.

To look up the data for a specific zip code and distance, you select the proper table, ex: 5miles

and then search for zip_1 = user_zip or zip_2 = user_zip

and you will find all records for all zips close to user_zip


How are you dealing with this issue?? The cos calculations are too intensive for real-time processing on a large site.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] ZIP code radius search? In reply to
Well, if you would like to see how I am doing with it, you can have a look
at supportmusicians.com, or I could send you the plugin to check it out.
I am in desperate need of an Image uploading plugin and have limit funds
avail right now, which is why I suggested an exchange :-)

You are way better at programming this than I am. I didn't put much effort into optimizing,
I was happy to get my ZipCodeSearch plugin working at a bearable speed.

Maybe you could test it on a larger site seems I don't have one.
My calculations are done on-the-fly, but the long/lat are added to each
links record via add/modify hooks. So when doing a search, I do not have
to look those up every time.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] ZIP code radius search? In reply to
What sort of image plugin? Just to add a logo?

When I analyzed the zip-code search feature, it's *not* as complicated as it seems <G> The only real issue is getting the zip code database, and the lat/lon, then processing a set of tables for look up efficiency.

The formula for doing radius search is provided.

The trick is doing an address to address search, as that requires a *very* accurate database and a lot of CPU to do real-time calculations. Probably something that would be passed off to a number-crunching server, which returns a value to the front end, but then again, that's not my area or need <G>

For my needs, being within a mile or two is close enough, and as the distance increases, up to 100 miles, even 10 miles off is not going to make a big difference. There would be more variations in the roads getting from A to B, or such.

Zip code searching is really (apparantly, unless I'm missing something huge) so trivial, it should be built into the links core release using one of the public databases as an "optional" field to enable in the admin. Once the database tables are installed, it's just a look up and an "IN" query.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] ZIP code radius search? In reply to
Quote:
What sort of image plugin? Just to add a logo?

Well, basically yes, but people tend to upload 300dpi images that are 5x7 or whatever.
I simply want to scale the image on upload and discard the original.

I am sure Image thumbnails are trival too once it is done :-)

Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] ZIP code radius search? In reply to
The Thumbs program will do what you want.

The Zipcode search *really* is trivial, as once the database is generated, it's just a key-field search, no additional routines need to be added to links, just a routine to generate the "IN" search, which gets passed to the search routines such as "ZIP_CODE in $list_of_Zips" for the WHERE routine.

The image program requires a lot more non-links work, and disk/file management, and in the past, working around some bugs/glitches, and before that, the fact most servers did *NOT* have any image processing routines, but now come pretty standard with Image::Magick (which is still like swatting a fly with a bazooka).

I *thought* the zip code program would be complicated, until I realized how it was done, or should be done, and why the programs came with the pre-developed 5,10,15, etc tables available.

For both programs, interface is the key issue.

I don't have a large zip code database, but I'm willing to test this out on someone's site that does have a large zip code database, and see if it works. It would add a few tables, and some hidden forms for testing, your users probably won't know it's there, and being tested, and it shouldn't do anything to your site, as all back-end code is in a .pm in the plugins area, and it's only modifying the search form for testing.

I have some pre-done tables, but will be looking at regenerating my own tables before the plugin is released.

This is a program that falls into the same class as my first "real" program waaaay back. We had TRS-80's (one was actually a Level II 16k machine <G>). The assignment was matrix arithmetic, doing a contact-spread of an alien disease. (Considering the time period, mid 70's, it was a bit prophetic).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.