Page 1 of 1

Search Results by Zip Code distance wise

Posted: Wed Apr 04, 2007 4:52 am
by basudeb
The search conditions are:

Business Name:

Zip:

With in(Miles)

Suppose i have given a business name say computer.
Zip code : 35034
and with in 20 miles

The result should show the business names whose distans lies with in 20 miles of the area whose zip is 35034.
Pls give me suggestion for that.

Posted: Wed Apr 04, 2007 5:25 am
by kpraman

Code: Select all

$query_search="SELECT bus_name FROM tbl_name WHERE dis <=20 AND zip=35034";

Posted: Wed Apr 04, 2007 8:05 am
by feyd
Do you have a database of these business' coordinates (in latitude and longitude)? If so, you can use the great circle algorithm to find them. If you do not, do so. Otherwise you will have to use a service to look up distance information.

Posted: Wed Apr 04, 2007 11:38 am
by RobertGonzalez
kpraman wrote:

Code: Select all

$query_search="SELECT bus_name FROM tbl_name WHERE dis <=20 AND zip=35034";
This will not work. In order to make the distance work properly you need to calculate the arc distance (as feyd stated, the great circle radius) then use that as your distance.

This is a somewhat involved process and can be very resource intensive.

Posted: Wed Apr 04, 2007 10:23 pm
by jwalsh
There are lots of examples of ways to calculate this. It's not very processor friendly as it involves heavy DB queries across thousands of rows.

I can't vouch for this resource, but it looks like a good starting point.

http://www.micahcarrick.com/v2/content/view/4/3/

Posted: Wed Apr 04, 2007 11:16 pm
by RobertGonzalez
I think Micah's script and data are a little outdated. I know there have been several posts around here about zip locators and scripts to interface with them. I wrote one and I know burrito wrote one also. Search a little around here, I am sure you'll find something.

Posted: Sun Sep 30, 2007 2:23 pm
by MicahCarrick
My script has been updated (the database) by end user contributions. It's now available at http://www.micahcarrick.com/04-19-2005/php-zip-code-range-and-distance-calculation.html

A user, Jeff Bearer, submitted a fix which reduced the db load a bit and made the code MUCH faster.

Personally, I haven't worked with this script in 2 years, however, I try to address user emails and comments as they come to me and update the code.

By the way, if y'all find other scripts and/or databases which are free that work well, I'd love to know. I'll link to them from my site.