# ZIP proximity based search. How to?

• May 8, 2005, 11:54
bigduke
ZIP proximity based search. How to?
I came across this on www.autotrader.com, a search based on proximity to a zip code. Any clues on how that could be done? I figured out a way for localized search based on IP but this just bowled me over. :confused:
• May 8, 2005, 11:57
Russeh
I would imagen its based on a calulation from both latitude and longitude values of both places
• May 8, 2005, 12:07
bigduke
Quote:

Originally Posted by Russeh
I would imagen its based on a calulation from both latitude and longitude values of both places

• May 8, 2005, 12:42
sweatje
Quote:

Originally Posted by bigduke

IIRC, you can download census data which give longitude and latitude for every postal code.
• May 8, 2005, 12:57
Dr Livingston
Quote:

I would imagen its based on a calulation from both latitude and longitude values of both places

There was a solution found if I remember, based on the actual calculation which may shed some light on it for you, if you care to go over the last couple of weeks threads, that is :)
• May 8, 2005, 18:38
Dylan B
Quote:

Originally Posted by Dr Livingston

There was a solution found if I remember, based on the actual calculation which may shed some light on it for you, if you care to go over the last couple of weeks threads, that is :)

Maybe?
• May 8, 2005, 19:06
fesh
I just started work on a zip code search. The formula used most often (due to computing power restraints) is

sqrt(x^2 + y^2)

where:

x = 69.1 * (lat2 - lat1)
y = 69.1 * (long2 - long1) * cos(lat1/57.3)

the way I do it is have a database with all the zip codes in it. Then I have the user input a zip. It finds the latitude and longitude of their zip then compares it through the above equation. This finds an approximation, not exact because of the computing restraints.
• May 9, 2005, 04:45
bigduke
Thanks fesh and Dylan thats what I was looking for :)
• May 9, 2005, 05:35
fesh
always glad to be of help.
• May 9, 2005, 08:44
DmS
You can also take a look here http://www.ozoneasylum.com/21781 , I did this sort of zip-distance search just like this a while back and collected a lot of good info plus some example code under that link. Including links to zip-code data (if they still work that is :) )
/Dan
• May 9, 2005, 09:19
Dr Livingston
Quote:

Maybe?
Spot on :)

Has anyone considered using or has used, a Web Service yet? Does anyone know of such a service exists?

Thanks :)
• May 9, 2005, 15:56
bigduke
Quote:

Originally Posted by Dr Livingston
Does anyone know of such a service exists?

Gives me an idea, how about implementing a web service for it ? :agree:
• May 10, 2005, 10:39
mlemos
Quote:

Originally Posted by bigduke
I came across this on www.autotrader.com, a search based on proximity to a zip code. Any clues on how that could be done? I figured out a way for localized search based on IP but this just bowled me over. :confused:

If you are looking for a solution specific for the US, you may want to take a look at these two classes: php Zip Locator and Zip Codes Range .

They both search a database of US zip codes and geographic coordinates to compute the distance. The first is more accurate but leads to table full scan on every search. The second is not very accurate, but for the purpose of excluding zip codes that are too far away it is much faster as it exclude entries that are too far in latitude and longitude, so with a range index on the coordinate fields it avoids table full scan and is obviously much faster despite it may end up including zip codes that are of your desired distance circle. A combination of both approaches would be ideal.

These solutions could be generalized for other countries in the world if you are able to find a database with zip codes for the countries you are interested.
• May 10, 2005, 17:11
absolution
Anyone had any luck finding Australian post codes with long and lat?
• May 10, 2005, 17:17
bigduke
mlemos excellent resource there mate, i hogged on it immediately.

Absolution, OZ land is still better organized and I'm sure there's one out there somewhere. Try asking the nearest post office for it.

I wonder if there even IS a list of zip codes by long at lat for India :p
• May 11, 2005, 07:56
Dylan B
Quote:

Originally Posted by bigduke
Thanks fesh and Dylan thats what I was looking for :)

No problem.