 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
05-01-2009, 02:36 PM
|
#1 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
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)
|
|
|
|
05-01-2009, 05:18 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
05-01-2009, 06:18 PM
|
#3 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
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.
|
Thanks VI, I'll check out that link.
So you think GPS is the key huh? If I can whip something up real quick I'll be sure to post it here..
|
|
|
|
05-01-2009, 06:24 PM
|
#4 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
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!!!
|
|
|
|
05-01-2009, 06:21 PM
|
#5 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
05-01-2009, 06:29 PM
|
#6 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Wildhoney
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.
|
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
There's 8 columns, I'll try to guess what they are:
#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.
|
|
|
|
05-01-2009, 06:49 PM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
- Field 1 - State Fips Code
- Field 2 - 5-digit Zipcode
- Field 3 - State Abbreviation
- Field 4 - Zipcode Name
- Field 5 - Longitude in Decimal Degrees (West is assumed, no minus sign)
- Field 6 - Latitude in Decimal Degrees (North is assumed, no plus sign)
- Field 7 - 1990 Population (100%)
- Field 8 - Allocation Factor (decimal portion of state within zipcode)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
05-01-2009, 06:59 PM
|
#8 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Wildhoney
- Field 1 - State Fips Code
- Field 2 - 5-digit Zipcode
- Field 3 - State Abbreviation
- Field 4 - Zipcode Name
- Field 5 - Longitude in Decimal Degrees (West is assumed, no minus sign)
- Field 6 - Latitude in Decimal Degrees (North is assumed, no plus sign)
- Field 7 - 1990 Population (100%)
- Field 8 - Allocation Factor (decimal portion of state within zipcode)
|
Thank you so kindly.... 
|
|
|
|
05-01-2009, 07:06 PM
|
#9 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
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%)
|
|
|
|
05-01-2009, 08:03 PM
|
#10 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
By "1990 Population" it means, the population in the year 1990 (that is when all this data is from).
|
|
|
|
05-01-2009, 08:07 PM
|
#11 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Yes, from the 1990 census im guessing.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
05-01-2009, 08:09 PM
|
#12 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Meaning the data is nearly 20 years old, it is probably too inaccurate to use.
|
|
|
|
05-01-2009, 08:13 PM
|
#13 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Salathe
By "1990 Population" it means, the population in the year 1990 (that is when all this data is from).
|
Quote:
Originally Posted by sketchMedia
Yes, from the 1990 census im guessing.
|
Quote:
Originally Posted by Village Idiot
Meaning the data is nearly 20 years old, it is probably too inaccurate to use.
|
WOW, that is OLD....oh well I don't need population numbers anyways, and zip codes don't change that often....I should be ok...
|
|
|
|
05-01-2009, 08:16 PM
|
#14 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by allworknoplay
WOW, that is OLD....oh well I don't need population numbers anyways, and zip codes don't change that often....I should be ok...
|
20 years is a very long time, they are probably quite different. Many areas that where not populated in 1990 are quire populated now, which would change zip codes by way of introducing new ones.
But for learning purposes, this should do.
|
|
|
|
05-01-2009, 08:36 PM
|
#15 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Village Idiot
20 years is a very long time, they are probably quite different. Many areas that where not populated in 1990 are quire populated now, which would change zip codes by way of introducing new ones.
But for learning purposes, this should do.
|
Exactly, I'm just messing around, this isn't part of any project for work or anything else of any importance....

|
|
|
|
05-01-2009, 09:09 PM
|
#16 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
05-01-2009, 09:12 PM
|
#17 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Wildhoney
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!
|
Thank you WH:
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....
|
|
|
|
05-13-2009, 03:55 PM
|
#18 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Location: Nashville, TN
Posts: 66
Thanks: 20
|
Quote:
Originally Posted by Wildhoney
Off topic:
Just don't be surprised if the zip codes of New Orleans still show up as being in New Orleans.
|
Eh? Whats that about?
__________________
I am not a programmer, nor do I play one on tv.
|
|
|
|
05-02-2009, 12:02 AM
|
#19 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
05-02-2009, 01:37 AM
|
#20 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|