Zip Code Range and Distance Calculation Class
Zip-Calc was created to convert a PHP class written by Quixotix in 2005 from MySQL to PostgreSQL. This class calculates the distance between U.S. zip codes and also finds all of the zip codes within a 9 given radius of a known zip code., (*1)
The CREATE
syntax for the database table used in the example is as follows:, (*2)
CREATE TABLE "public"."maps" ( zip_code_id SERIAL PRIMARY KEY, zip_code TEXT NOT NULL, city TEXT NOT NULL, county TEXT NOT NULL, state_name TEXT NOT NULL, state_prefix TEXT NOT NULL, area_code TEXT NOT NULL, time_zone TEXT NOT NULL, lat NUMERIC(10,7) NOT NULL, lon NUMERIC(10,7) NOT NULL );
Install the project via Composer:, (*3)
composer create-project austintoddj/zip-calc
Once inside your database, import the data/maps.sql
file included in the project. If you need some assistance on getting up and running with a PgSQL database, find out more on Digital Ocean., (*4)
In the example.php
file, you will need to update the $connectionString
., (*5)
If you followed the steps up to this point correctly, you should see the following when you access example.php
from a browser:, (*6)
, (*7)
Zip-Calc is open-sourced software licensed under the MIT license., (*8)