![]() |
Locations based on ZIP code...
Hey guys,
I don't want the code, but would like to generally get an idea of how this works. You know how when you search for a car, it asks for your zip code? And then it allows you to choose 5 miles radius from you? 10 miles, 20 miles etc... I was just thinking, how exactly does that work? Say you live in Beverly Hills 90210. So now I have an account profile that shows your postal code is 90210. I can have another table called "locations" that would have the 90210 zip code too, but that wouldn't necessarily tell me if those locations were 1, 5 10, 30 miles near me... So what is the "design" algorithm for displaying radius? Is this something where I have to use Google's map API to do some fancy calculation? (i'm not sure google's map api even exist, just theorizing) |
I've never done this, so this is just me theorizing. Zip codes do not indicate a location by themselves. You have to have a database that have the zips and their corresponding GPS locations (many are for sale, a free one is available at http://www.census.gov/tiger/tms/gazetteer/zips.txt ). Then using basic algebra, you use the following formula
r^2 <= (x-h)^2 + (y-k)^2 r being your radius, x and y being your testing points and h and k being your zip codes location. If a real number is returned x and y are within your circular radius. There are probably algorithms to ensure you are only checking ones in the right geographic area. |
Quote:
So you think GPS is the key huh? If I can whip something up real quick I'll be sure to post it here.. |
I used to have a database of all the UK postcodes, and the distances were calculated using the longitude and latitude values.
The algorithm was fairly simple, but I'm unable to locate the script I did at the moment. |
Oh and thanks for the link, I didn't know this data was free, I actually had my company PAY for ZIP codes and....drum roll....it doesn't even include GPS coordinates!!!
|
Quote:
Ohhh!! I don't want the script, since you say it's fairly simple I hope I can learn to make my own....just some guidance? From the link that VI provided, here's the layout, but I don't know what is what? Code:
"01","35004","AL","ACMAR",86.51557,33.584132,6055,0.001499#1 = 01 --> not a clue? But it doesn't look all that important. #2 = 35004 --> ZIP code #3 = AL --> This is the state. #4 = ACMAR --> This is the town #5 = 86.51557 --> nope, don't know. #6 = 33.584132 --> nope, don't know. #7 = 6055 --> nope, don't know. #8 = 0.001499 --> nope, don't know. |
|
Quote:
Thank you so kindly.... :-D |
Hey WH:
What do you mean by 1990 population? How did you get the 1990? And I am assuming it's 1,990.... Field 7 - 1990 Population (100%) |
By "1990 Population" it means, the population in the year 1990 (that is when all this data is from).
|
Yes, from the 1990 census im guessing.
|
Meaning the data is nearly 20 years old, it is probably too inaccurate to use.
|
Quote:
Quote:
Quote:
|
Quote:
But for learning purposes, this should do. |
Quote:
^^ |
Off topic:
Just don't be surprised if the zip codes of New Orleans still show up as being in New Orleans. Please keep us up-to-date with this research of yours! |
Quote:
I will try to put up a page for you guys to play with. Any code I come up with I will most definitley share with you guys... The only thing is that it's US based...I guess I need to think bigger and cover the world!??? Small steps first.... |
You're right. I suppose either GPS co-ordinates or traditional longitude and latitude would be more than sufficient. It's just getting the data -- the zip codes and postcodes (and any others that other countries use) to correlate with either of the two aforementioned.
I don't think it's going to be easy! However, once you have that data, the zip codes and postcodes become one (not in a Buddhist sense) and become irrelevant insofar as the algorithm is concerned. Those codes are used to retrieve L&L or GPS co-ordinates and the system uses those to calculate distance. |
Zip codes are mainly for the US postal service, towns are a better way to go worldwide.
Proficiently doing towns in the world would require a well designed database and an optimized script because you would be working with tons of different locations and you have to compare them against each other (a good narrowing algorithm would be required). I would stick to zip codes for now, but having something that could do a good portion of the world would be an awesome project to take on. As wild put it though, zip codes are just a way to reference to the GPS, so you could easily use the same theory to power a town based search. |
After doing some research on this, this can get extremely complicated. I've seen some code that use COS, SIN and other types of math formulas I haven't done since high school..
Anyways, for you UK folks, I found this website if any of you are interested. http://www.milldo.com/en16_uk_post_codes_database.htm And here is the formula that seems to be the most accurate.. http://en.wikipedia.org/wiki/Haversine_formula It's all just a bit too much for my current skillsets right now... |
| All times are GMT. The time now is 03:55 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0