Re: zip codes and lat/longs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After reading this I decided to figure out what the issue was.

It was the MySQL result set. Somehow the columns changed and messed up
the float values. So I just whipped this up quick to reload the data
(and possibly update it too)

Here's the quick-and-dirty:

1) download ZCTA (the text version) from
http://www.census.gov/geo/www/gazetteer/places2k.html
2) run this

db_query("TRUNCATE TABLE data_zips");

$fp = fopen('zcta5.txt', 'r');
while(!feof($fp)) {
        $line = fgets($fp, 2048);
        $line = chop($line);
        $zip = substr($line, 2, 5);
        $lat = substr($line, 137, 9);
        $long = substr($line, 146, 12);
        db_query("INSERT INTO data_zips(zip, latitude, longitude)
VALUES('$zip', '$lat', '$long')");
}
fclose($fp);

schema:

CREATE TABLE `data_zips` (
  `zip` mediumint(5) unsigned zerofill NOT NULL default '00000',
  `latitude` float(9,6) NOT NULL default '0.000000',
  `longitude` float(9,6) NOT NULL default '0.000000',
  PRIMARY KEY  (`zip`),
  KEY `latitude` (`latitude`),
  KEY `longitude` (`longitude`));

I believe now you have everything you need :)


On 12/6/07, Daniel Brown <parasane@xxxxxxxxx> wrote:
> On Dec 5, 2007 8:58 PM, tedd <tedd@xxxxxxxxxxxx> wrote:
> > Hi gang:
> >
> > I'm entertaining how to determine what zip codes fall within a 50
> > mile radius of another zip code.
> >
> > Anyone done this before?
> >
> > Also, does anyone have any sources for zip codes and lat/long databases?
>
>    Tedd,
>
>    I have all of this in a MySQL database already, with census
> information, water table info, and more.  If you want to take a look,
> let me know and I'll give you a peek via phpMyAdmin to see if it'll
> match your needs.
>
>    For you, it's free.  All else must PAY!!!!  ;-P
>
> --
> Daniel P. Brown
> [Phone Numbers Go Here!]
> [They're Hidden From View!]
>
> If at first you don't succeed, stick to what you know best so that you
> can make enough money to pay someone else to do it for you.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux