Search Results by Zip Code distance wise

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

Search Results by Zip Code distance wise

Post 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.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

Code: Select all

$query_search="SELECT bus_name FROM tbl_name WHERE dis <=20 AND zip=35034";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post 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/
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
MicahCarrick
Forum Newbie
Posts: 23
Joined: Sat Apr 09, 2005 5:40 pm

Post 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.
Post Reply