Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Zip Code Module?

by powerhouse (Friar)
on Dec 17, 2004 at 00:07 UTC ( [id://415517]=perlquestion: print w/replies, xml ) Need Help??

powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

I am just wondering, I see a lot of sites these days, that have it where you can give a form your zip code and it will lookup the city that corresponds to that zip code, and if a few choices it will ask them, which city it is.

Is there a module that can do this, or where can I find information on a way to do this?

I searched Cpan for zipcode and state but could not find anything useful.

Any tips you have would be very much appreciated!


thx,
Richard

Replies are listed 'Best First'.
Re: Zip Code Module?
by sifen (Beadle) on Dec 17, 2004 at 00:35 UTC

    I think Geo::PostalCode would be at least a look. It reads the zipcode/city data from Bearkly DB's that you can get from http://www.census.gov/geo/www/tiger/zip1999.html.

    It seems pretty stright forwards, the relivant section from the docs is below:

    $gp = Geo::PostalCode->new(db_dir => $db_dir);

    Returns a new Geo::PostalCode object using the postalcode.db, latlon.db, and city.db Berkeley Database files in $db_dir.

    $record = $gp->lookup_postal_code(postal_code => $postal_code);

    Returns a hash reference containing four keys:

    * lat - Latitude
    * lon - Longitude
    * city - City
    * state - State two-letter abbreviation.

    Hope that's of some use to you. . .

      I use this module frequently, and it works great. I'd highly recommend it. You'll need to download the postal code data before it will complete "make test" succesfully.
        What do you mean, "download the postal code data"?

        I tried this module, I installed it, using WHM (a cPanel Product) with the Install a Perl Module, it appeared to work ok, however, when I use the 'sample' code:
        use Geo::PostalCode; my $gp = Geo::PostalCode->new(db_dir => "."); my $record = $gp->lookup_postal_code(postal_code => '07302'); my $lat = $record->{lat}; my $lon = $record->{lon}; my $city = $record->{city}; my $state = $record->{state}; my $distance = $gp->calculate_distance(postal_codes => ['07302','100 +04']); $record = $gp->lookup_city_state(city => "Jersey City",state => "NJ" +); $lat = $record->{lat}; $lon = $record->{lon}; my $postal_codes = $record->{postal_codes}; $postal_codes = $gp->nearby_postal_codes(lat => $lat, lon => $lon, distance => 50); print qq~<br> City is ~ . $city . qq~<br> State is ~ . $state . qq~<br> Latitude is ~ . $lat . qq~<br> Longitude is ~ . $lon . qq~<br> <br> Nearby Zips are: $postal_codes~;
        (ran as a test) and I had this 'output':
        City is
        State is
        Latitude is
        Longitude is

        Nearby Zips are: ARRAY(0x8674890)

        So, could what you said, be the reason why it's not working?

        I would appreciate your help.
        thx,
        Richard
Re: Zip Code Module?
by kvale (Monsignor) on Dec 17, 2004 at 00:26 UTC
    I don't know of any module that has its own zipcode database, but there are CPAN modules, like Scrape::USPS::ZipLookup::Address, that scrape a USPS web page to extract city info. It is suitable for non-commerical use -- look at the site for the full terms of use.

    -Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://415517]
Approved by superfrink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-19 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found