MicahCarrick / PHP-ZipCode-Class

Zip Code Range and Distance Calculation Class for PHP 5
68 stars 24 forks source link

Many zipcodes are getting skipped in range search #4

Open jasonseabaugh opened 12 years ago

jasonseabaugh commented 12 years ago

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.

msundquist commented 12 years ago

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.

JayLevine commented 12 years ago

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

swedub commented 11 years ago

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.