Welcome Guest, Not a member yet? Register   Sign In
Calculating distance between two points, finding zip codes/cities, etc. (US cities only)

Hi everyone.
This is my real "contribution" to CI community. So excited! Smile

A long time ago, I developed SpeedyWord.com (a site dedicated to helping people find local, trustworthy service based professionals like car mechanics and nannies) using Micah Carrick's PHP Zip Code Range and Distance Calculation script. It's an awesome script.

Since i'm doing a lot of CI work now, I figured I might as well port this. If you're developing a locale-based service web app, this is really cool tool.

1) Download the zip file from the site
2) Load your MySQL database with the .sql files (as instructed in the zip file)
3) Put the plugin (see attached) into plugin directory
4) Put the model (see attached) into model directory
5) In your page controller, do

$z = new Zipcode();

Hey CI forum admin: How do I attach files? I can't seem to copy /paste the code b/c it's too long.. plus it won't let me attach .php files. I tried renaming it to JPG but it reads the MIME data and won't let me upload.

[eluser]Phil Sturgeon[/eluser]
Put the files in a zip file and upload that. You cant upload PHP or other executables for obvious security reasons.

Tried that too. Error message:

Error Message:  The filetype you are attempting to upload is not allowed
Allowed Filetypes: image

[eluser]Phil Sturgeon[/eluser]
Ahh strange, well obviously the EllisLabs types dont want the forums to play file host for this sort of thing. Make a page on the Wiki and upload it there instead.

I need this!

What I did to get zipcode calculations working on my site, with zipcode-1.2.0.zip. Don't forget to load the zipcodes into your database.

Download the zip file from http://www.micahcarrick.com/04-19-2005/p...ation.html

To use the zipcode.class.php file, rename it to filename_helper (I used zipcodecalc_helper) and put it in your application/helper folder.

In your controller initialize the helper/class.
//Single helper
//OR helper array

In your controller or view, you can then do (taken from the demo file)
$z = new zipcode_class;

echo '<h3>A sample getting all the zip codes withing a range: 2 miles from 97214</h3>';

$zips = $z->get_zips_in_range('97214', 2, _ZIPS_SORT_BY_DISTANCE_ASC, true);

if ($zips === false) echo 'Error: '.$z->last_error;
else {
   foreach ($zips as $key => $value) {
      echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>97214</b>.<br />";
   // One thing you may want to do with this is create SQL from it. For example,
   // iterate through the array to create SQL that is something like:
   // WHERE zip_code IN ('93001 93002 93004')
   // and then use that condition in your query to find all pizza joints or
   // whatever you're using it for. Make sense? Hope so.
   echo "<br /><i>get_zips_in_range() executed in <b>".$z->last_time."</b> seconds.</i><br />";

Hope this helps!

I also use Michael Carrick's implementation for production use. So far its just great for my search by zip-code features on my newest website.

Haven't had a problem with it yet, very easy to use. Until its available on the wiki you can download directly from the original posters link and follow his directions - nothing much is needed to get it working in CI, it is quite well written.

Does anyone still need this? Let me know.. i'll zip it somewhere and post

I would love to get hold of this.

Theme © iAndrew 2016 - Forum software by © MyBB