ZIP Code Boundaries Database
A MySQL database for creating ZIP Code outlines in Google Maps and other mapping applications.
These ZIP Code boundaries are derived from the U.S. Census Bureau's Zip Code Tabulation Areas (ZCTAs).
Purchase
- $750 : MySQL (4.0 or later) database of ZIP Code boundaries. Download database sample and see example below.
Purchase at eSellerate - $250 : MySQL (4.0 or later) database of U.S. cities with zip codes. Download database sample and see example below.
Purchase at eSellerate - $250 : PHP Class for use with Google Maps (requires both databases). See code examples below.
Purchase at eSellerate - Hourly Rate : Do you need this data in other formats or custom application development? Get in touch with developer John Wehr via email at johnwehr@gmail.com.
Important Note
ZIP Codes are not area or line geographies but rather collections of addresses used by the U.S. Postal Service. Therefore this database does not have boundaries for 10,068 ZIP Codes. These include 2,523 ZIP Codes that serve specific companies or organizations with high volumes of mail and 6,419 ZIP Codes dedicated to Post Office (PO) Box and/or general delivery addresses primarily located in areas otherwise served by rural route or city style mail delivery.
Note Google's documentation on using polylines with Internet Explorer.
Combined PHP File
<head>
<script type="text/javascript">
// <![CDATA[
<?php
require_once 'ZipBoundaries.php';
$zb = new ZipBoundaries( "30306" );
$zb->mysql_connect( "db_host", "db_username", "db_password", "db_name" );
$zb->js(true);
?>
window.onload = function() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
drawBoundaries( map );
}
}
// ]]>
</script>
</head>
Using Smarty with separate JS, PHP and template files.
// In a PHP file:
<?php
require_once 'smarty/Smarty.class.php';
require_once 'ZipBoundaries.php';
$t = new smarty;
$zb = new ZipBoundaries( "30306" );
$zb->mysql_connect( "db_host", "db_username", "db_password", "db_name" );
$t->assign('javascript', $zb->js());
?>
// In a template
<head>
<script type="text/javascript">{$javascript}</script>
</head>
// In an external Javascript file:
<script type="text/javascript">
// <![CDATA[
window.onload = function() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
drawBoundaries( map );
}
}
// ]]>
</script>
Installing the sample databases
wehr@johnwehr:~$ mysql --user=db_user --pass=db_pass Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 122245 to server version: 5.0.18-Debian_7-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database zip_boundaries; Query OK, 1 row affected (0.02 sec) mysql> exit Bye wehr@johnwehr:~$ mysql --user=db_user --pass=db_pass zip_boundaries < zip_boundaries_sample.sql wehr@johnwehr:~$ mysql --user=db_user --pass=db_pass zip_boundaries < zips_sample.sql wehr@johnwehr:~$ mysql --user=db_user --pass=db_pass Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 122254 to server version: 5.0.18-Debian_7-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use zip_boundaries; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT name, state FROM zips WHERE zip='35221'; +------------+-------+ | name | state | +------------+-------+ | BIRMINGHAM | AL | +------------+-------+ 1 row in set (0.00 sec) mysql> SELECT lat, lng, start FROM zip_boundaries WHERE zip='35221' ORDER BY id; +------------------+-------------------+-------+ | lat | lng | start | +------------------+-------------------+-------+ | 33.4443896820988 | -86.9011655892784 | 1 | | 33.489106 | -86.876491 | 0 | | 33.487006 | -86.876191 | 0 | | 33.478006 | -86.883991 | 0 | | 33.469007 | -86.883091 | 0 | | 33.475006 | -86.874391 | 0 | | 33.471607 | -86.874391 | 0 | | 33.470857 | -86.876855 | 0 | | 33.471707 | -86.878091 | 0 | | 33.471507 | -86.878891 | 0 | | 33.468107 | -86.882891 | 0 | | 33.455307 | -86.882991 | 0 | | 33.453007 | -86.885091 | 0 | | 33.449907 | -86.886991 | 0 | | 33.443208 | -86.890091 | 0 | | 33.440608 | -86.889691 | 0 | | 33.438408 | -86.890191 | 0 | | 33.438044 | -86.891351 | 0 | | 33.438044 | -86.891351 | 0 | | 33.435016 | -86.891356 | 0 | | 33.424205 | -86.904463 | 0 | | 33.424137 | -86.91386 | 0 | | 33.431508 | -86.906091 | 0 | | 33.433008 | -86.905491 | 0 | | 33.435708 | -86.908591 | 0 | | 33.436508 | -86.912591 | 0 | | 33.438908 | -86.915491 | 0 | | 33.44022 | -86.91561 | 0 | | 33.44022 | -86.91561 | 0 | | 33.443408 | -86.911991 | 0 | | 33.451344 | -86.918426 | 0 | | 33.45246 | -86.918136 | 0 | | 33.451708 | -86.913191 | 0 | | 33.462507 | -86.898091 | 0 | | 33.470107 | -86.890691 | 0 | | 33.483396 | -86.880812 | 0 | | 33.483396 | -86.880812 | 0 | | 33.489106 | -86.876491 | 0 | +------------------+-------------------+-------+ 38 rows in set (0.00 sec)