# Thread: ZIP proximity based search. How to?

1. ## 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.

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

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

4. Originally Posted by bigduke
IIRC, you can download census data which give longitude and latitude for every postal code.

5. 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

6. 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?

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

8. Thanks fesh and Dylan thats what I was looking for

9. Originally Posted by bigduke
Thanks fesh and Dylan thats what I was looking for
No problem.

10. always glad to be of help.

11. 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

12. Maybe?
Spot on

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

Thanks

13. 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 ?

14. 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.
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.

15. Anyone had any luck finding Australian post codes with long and lat?

16. 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•