Search by zip code

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Does anyone know if there are any modules available that enable searches by  
zipcode for proximity?  I want the user to enter a zipcode and then I want  
to somehow search for all entries in a database that are within, say, 25  
miles of that zipcode.  This is done in many, many sites on the net and I am  
wondering if anyone knows of an add-on package to make it happen.  No sense  
in re-inventing the wheel.


Re: Search by zip code

Shelly wrote:
Quoted text here. Click to load it


I don't have the code handy - but it's not hard to develop.

Basically store zip codes, longitude and latitude in a database (i.e. MySQL).

Take the long/lat of the entered zipcode.  Create minimum and maximum long/lat  
for your desired radius (a little searching of the internet will give you the  
equations).  Then search for any zip code with long/lat within the given range.

Finally, for fine tuning, check the distance of the returned zip code against  
the entered zip code (similar formulae).

Last time I did it it was all of about six lines of code and ram in < 1 sec.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Search by zip code

I use this one for perl and call it by shell_exec() in my php script :

I am sure there must be an all php solution, but this works fine for
what I needed.

Re: Search by zip code


Shelly wrote:
Quoted text here. Click to load it

Sure, try either of these packages:

Class: php Zip Locator

Class: Zip Codes Range


Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP

PHP Reviews - Reviews of PHP books and other products

Metastorage - Data object relational mapping layer generator

Re: Search by zip code

Quoted text here. Click to load it

Thank you.  I recently subscribed to PHPclasses.  The
looks like exactly what I need.  I do need a little education, however.  So,  
if you could either point me to the proper place or explain it to me, I  
would be appreciative.

1 - That class has a require of DB.php.  There was none in the download.  
Where can I find that one.

2 - It has the the syntax   "$db =& DB::connect(DSN);" .    What is the  
"::"?  What is the "DB"?

3 - DSN was defined as "define ('DSN', 'pgsql://user@localhost/database');".  
Can you explain the second argument? It look like a URL.

4 - In using this class, do I  simply create a variable with something like:
        $my_var = new ZipCodesRange(<the arguments>);
     and then access the zipcodes that satisfy as:
        $my_var->zipcodes[$i]  ?

5 - Can the zipcode table simply be a table in my main database?

These may seem like obvious questions to you, but it is questions like these  
that have blocked my using the PHPclasses stuff.  It seem like an  
exceptionally rich collection of material.


Re: Search by zip code

Shelly wrote:
Quoted text here. Click to load it

Quoted text here. Click to load it

   Its an URI, not URL.  PEAR::DB can take an argument as either a hash,  
or a URI.  It means "connect to a postgresql db as "user", on machine  
"localhost", and access database called "database".

Quoted text here. Click to load it

   "new" will create a new instance from class ZipCodeRange

Quoted text here. Click to load it

   Sure.  You can store just about any kind of information in a db ;-)

Site Timeline