• Login
  • Registration
  • RSS

Clone Site

Free Download Clone Site and Complete Site Script
  • Home
  • E-Shop
  • Most Viewed
  • Most downloaded
  • Best entries
  • Contact Us
Main » Files » Site Script » Site Services[ Add new entry ]

PHP Zip Code Range and Distance Calculation  

Download

PHP Zip Code Range and Distance Calculation

This is a PHP class to do various calculations with zip codes. It's primary purposes are to calculate the distance between two zip codes and to extract all the zip codes that are within a range of a given zip code. All calculations are based on lattitude and longitude coordinates stored in the database. Included is a class file, demonstration file, and the sql files required to create and populate the MySQL tables.


Setting up the Database


There are 6 files in the /sql
directory which contain SQL statements intended for a MySQL database
(though they should work just fine for any SQL database). The zip code
database consists of over 40,000 records which would be too large a file
for many configurations of phpMyAdmin. Therefore, I have broken the
data into records of 10,000 resulting in 5 files. In phpMyAdmin, you can
import these 6 files 1 at a time using the ''Import'' tab. You MUST
import the ''create_table.sql'' file first, then each of the data files.

create_table.sql
data_1.sql
data_2.sql
data_3.sql
data_4.sql
data_5.sql

The database has changed since the last version. The data itself is
comprised of data from multiple sources starting with the 2000 and 2004
US Census data. Unlike version 1.x of this class, the database is no
longer comprised of a state AND zip_code table, but a single zip_code
table. Additionally, the table is created with an index on the zip_code
column.

The Class: zipcode.class.php


Constants


// constants for setting the $units data member 
define(''_UNIT_MILES'', ''m'');
define(''_UNIT_KILOMETERS'', ''k'');

// constants for passing $sort to get_zips_in_range()
define(''_ZIPS_SORT_BY_DISTANCE_ASC'', 1);
define(''_ZIPS_SORT_BY_DISTANCE_DESC'', 2);
define(''_ZIPS_SORT_BY_ZIP_ASC'', 3);
define(''_ZIPS_SORT_BY_ZIP_DESC'', 4);

// constant for miles to kilometers conversion
define(''_M2KM_FACTOR'', 1.609344);

Data Members



















decimals Read/Write. When returning distance values, this variable determines how many decimal places the result should be rounded to.
last_error Read-only. Holds a string value of the last error that occured. This
can be used should a method return an error value to get a human
readable version of the error.
last_time Read-only. Holds the last method execution time used to debug the efficiency of the get_zips_in_range() method.
units Read/Write. Holds the type of units to show results in. Must be either _UNITS_MILES or _UNITS_KILOMETERS

Methods

























calculate_mileage($lat1, $lat2, $lon1, $lon2) Calculates the mileage between the two lattitude/longitude points: $lat1/$lon1 and $lat2/$lon2.
chronometer() Chronometer function from PHP manual used to time execution of get_distance() and get_zips_in_range() methods.
get_distance($zip1, $zip2) Returns the distance between the two zip codes: $zip1 and $zip2. If
there is an error, false is returned. Since the function can return 0
when 2 zips are the same, you must evaluate for an error condition
using:
if (get_distance($zip1, $zip2) === false) // error condition
get_zip_details($zip) Returns the details about the zip code: $zip. Details are in the form of a keyed array. The keys are: latitude, longitude, city, county, state_prefix, state_name, area_code, and time_zone. All are pretty self-explanitory. Returns false on error.
get_zip_point($zip) Gets the lattitude and longitude coordinates of the given zip code as a keyed array. The keys are: lat and lon. Returns false on error.
get_zips_in_range($zip, $range, $sort,$include_base) Finds all zip codes within $range from $zip as a keyed array sorted
by $sort. If $include_base is set to true or not specified, then $zip is
included in the results. If it is set to false, then $zip is excluded
from results. Possible values for $sort are: _ZIPS_SORT_BY_DISTANCE_ASC (default), _ZIPS_SORT_BY_DISTANCE_DESC, _ZIPS_SORT_BY_ZIP_ASC, _ZIPS_SORT_BY_ZIP_DESC.
The return value is a keyed array where the key is the zip code and the
value is the distance from the base zip $zip. Returns false on error.

  • 1
  • 2
  • 3
  • 4
  • 5
Category: Site Services | Added by: karwanpro | Tags: PHP, ZIP, Distance, calculation, Range, code
Views: 1119 | Downloads: 371 | Rating: 0.0/0

Categories

╠═ clone site
    ╙─ CMS
    ╙─ Site Services
    ╙─ Mail and Chat
    ╙─ Game and Fun
    ╙─ Search Engines
    ╙─ Internet Services
    ╙─ Social Preferences
    ╙─ Business and money
    ╙─ Upload and Download
╠═ Site Script
    ╙─ Chat
    ╙─ Vedio
    ╙─ Forum
    ╙─ Site Services
    ╙─ Internet Services
    ╙─ Social Preferences
    ╙─ Business and money
    ╙─ Upload and Download
╠═ Site Template
    ╙─ PSD Template
    ╙─ uCoz Template
    ╙─ Flash Template
    ╙─ HTML Template
    ╙─ Joomla Template
    ╙─ Blogger Template
    ╙─ WordPress Theme
╠═ Mobile Template
    ╙─ HTML Template
╠═ Site Tools
    ╙─ PSD
    ╙─ Vector
    ╙─ PNG Icon
    ╙─ site Applications

Search

Site Tools

  • Crate Hit counter
  • Crate Web Clock
  • Crate Weather for your site
  • Our poll

    Do you like to put a forum on the site?
    Results | Polls archive
    Total of answers: 121

    Login

    Old login form
    Email:
    Password:
    Lost password | Sign Up
    or
    Popular Clone Site
  • Twitter.com Clone Site (54239)
  • Gmail.com Clone Script (47414)
  • xdrive.com clone site (40645)
  • adf.ly Clone Site (33979)
  • beemp3.com clone site (27668)
  • omegle.com clone site (25383)
  • myspace.com Clone Site (19577)
  • yousendit.com clone site (19195)
  • Fonts Site Script (18074)
  • magicbricks clone (17007)
  • Statistics
  • Total online: 2
  • Guests online: 2
  • Users online: 0
  • Comments: 1323
  • Script & Template: 293
  • Site: 34
  • E-Shop: 3
  • Total users: 289
  • Last User: ejsvtjlutpt
  • Frendly Site
  • YourHost (536)
  • Bluelog (579)
  • Download Gratis Apk Mods ... (592)
  • TrK, inc. Official Site (673)
  • Get free Unlimited Hostin... (737)
  • Chili Host Network (702)
  • Download Software serbian... (902)
  • Bdoz Nudel file Searcher (672)
  • Cracks Net - Free Downloa... (803)
  • Submit Your Site
  • Advertising

    Theme Design by The Theme Foundry | Hosted by uCoz | Programming by Karwanpro

    Copyright Clone Site © 2010 - 2025