PHP-ZipCode-Class icon indicating copy to clipboard operation
PHP-ZipCode-Class copied to clipboard

Many zipcodes are getting skipped in range search

Open jasonseabaugh opened this issue 13 years ago • 3 comments

Firstly, thanks for the code. I'm using the getZipsInRange to find all zipcodes with X miles of a given zipcode. I get a large number of results, and it seems fairly accurate at the "local" level, but anything further out, say 50 to 100 miles or more, many zipcodes get skipped. In fact, my tests reveal that when trying to get all zipcodes within 25000 miles (which should cover the entire planet) from a database of 42,624 entries, I only get 2602 results. That's a margin of error of 84 percent. Does this sound in line with known limitations of the class or am I clearly doing something wrong?

I am using the obsolete database that came with the project and I have made the corrections listed from the previously posted issues.

jasonseabaugh avatar Jun 29 '12 22:06 jasonseabaugh

The query in class method "getZipsInRange" appears to be fixed at a 25-mile range. You'll see something like: "ROUND({$this->lat} - (25 / 69.172), 4)", with multiple occurrences of "25." I believe these need to be replaced with the $range_to variable.

Looking a bit closer, it seems the conditions: "lat/lon BETWEEN ..." aren't necessary in this query. I removed these conditions from the WHERE clause, leaving the comparison between $range_to and $range_from, and it appears to work properly.

Either of the above appears to solve the problem.

msundquist avatar Aug 11 '12 09:08 msundquist

Hey Guys, thanks for the answer on this one. It was great to see the solution here. I replaced several "25"s in the code where you mention...problem solved.

Jay

JayLevine avatar Oct 05 '12 17:10 JayLevine

Wow, I should have looked here months ago when I first stumbled on this. I just tried taking a crack at it again and finally saw this thread. Thanks for the info! Now I feel comfortable using this.

I just signed up to Gihub to reply to this. I'm eager to contribute as soon as I wrap my head around the details on contributing code to projects.

swedub avatar Apr 03 '13 18:04 swedub