I have found this popular PHP/MySQL Script called Zip Location by SaniSoft and it works great besides one thing: It doesn’t in some instances.
It seems that any radius under 20 miles returns the same amount of zip codes as 20 miles. I have searched all over google, but to no avail and I was wondering if someone had some insight on this situation.
I would rather figure out this problem before having to pay for a program, and I could also use the learning experience. The database is a list of zip codes and longitudes and latitudes of each zip code. The script uses a method that determines the distance around the zip code entered and returns the zip codes in that radius based on their lon/lat.
Thank you!!
Edit:
From using the distance function that the script provides I have discovered that the distance between the Zip Codes that the program gives me and my zip code are coming up as 0 miles.
MAJOR UPDATE
From research it turns out that the database has duplicate lat/lon values. Please be aware of this when using Zip Locator. Although the PHP does its job, you will need to find a new Database of zip codes. I will post my findings at a later date.
Second try!
Seeing your edited problem statement, I’d look at how you assign your zip values.
Lots of errors can be introduced if your zip codes are integers instead of strings. The biggest problem is that American zip codes can start with 0.
The examples in ziptest.php aren’t good, since the treat zips as integers. When you try to describe my own zip code with an integer:
Its interpreted by PHP as the octal value 2446. phpZipLocator the uses that value as a string without any explicit conversion. PHP therefore gives it the decimal value of octal 2446 as a string (1318) which is not a zip code at all.
Instead of notifying that it didn’t find a zip code, phpZipLocator does a radius search of all zip codes within a given radius of something that doesn’t exist, which it decides should be 1.
If I set the zip code using a string
I get the correct result.
IMHO it seems like phpZipLocator could use a little work.