Welcome Guest!
Please login
If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:
- Receive Fast Advice
- Learn Programming Languages
- Get Professional Website Reviews
- Quick Troubleshooting Assistance
|
|
Help! Working With Post Codes Work?
This is a discussion on Help! Working With Post Codes Work?, within the Web Design in General section. This forum and the thread "Help! Working With Post Codes Work?" are both part of the Designing Your Website category.
![]() ![]() |
Apr 6 2008, 03:22 PM
Post
#1
|
|
|
Master of the Universe ![]() Posts: 1,298 Joined: 15-February 08 From: London, England |
Has anyone worked with postcodes before?
What I want to do is create a regional website. When users sign up they will be required to put in their postcode. This postcode will then be validated to confirm the postcode is within the region. For reason's I am keeping me to myself, I need to be able to determine the distance between two postcodes. These do not need to be exact but I need to be able to calculate the distance to within a mile. Right, question 1. Where do I get a definitive list of postcodes from? Would I have to purchase a list from my local council? Question 2. How do I calculate the distance between two points? Help as always is much appreciated. -------------------- |
|
|
Apr 6 2008, 03:23 PM
Post
#2
|
|
|
Rapid Squeezer ![]() ![]() ![]() ![]() Posts: 128 Joined: 16-February 08 |
Something like Google Maps springs to mind, but that might not be possible.
-------------------- |
|
|
Apr 7 2008, 01:10 AM
Post
#3
|
|
![]() Rapid Squeezer ![]() Posts: 197 Joined: 14-February 08 From: Willich, Germany |
This sounded interesting... And I'm at school and bored right now, so I did some research.
Option 1: Use existing services like: http://www.timeanddate.com/worldclock/distance.html http://www.daftlogic.com/projects-google-m...-calculator.htm http://www.geobytes.com/citydistancetool.htm You can pass the post codes via URL and then parse the generated contents.... However, the sites might not allow that, especially if you have a large # of queries.... Option 2: If you have the latitude and longitude of each post code then you can calculate the distance yourself. I found a C++ function originally from http://www.zipcodeworld.com/. Looks like an interesting company if you are willing to spend money on this. If you want I could probably convert this to PHP.... It's not such a complicated function: http://www.zipcodeworld.com/samples/distance.c.txt CODE /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: :*/ /*:: This routine calculates the distance between two points (given the :*/ /*:: latitude/longitude of those points). It is being used to calculate :*/ /*:: the distance between two ZIP Codes or Postal Codes using our :*/ /*:: ZIPCodeWorld(TM) and PostalCodeWorld(TM) products. :*/ /*:: :*/ /*:: Definitions: :*/ /*:: South latitudes are negative, east longitudes are positive :*/ /*:: :*/ /*:: Passed to function: :*/ /*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/ /*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/ /*:: unit = the unit you desire for results :*/ /*:: where: 'M' is statute miles :*/ /*:: 'K' is kilometers (default) :*/ /*:: 'N' is nautical miles :*/ /*:: United States ZIP Code/ Canadian Postal Code databases with latitude & :*/ /*:: longitude are available at http://www.zipcodeworld.com :*/ /*:: :*/ /*:: For enquiries, please contact sales@zipcodeworld.com :*/ /*:: :*/ /*:: Official Web site: http://www.zipcodeworld.com :*/ /*:: :*/ /*:: Hexa Software Development Center © All Rights Reserved 2004 :*/ /*:: :*/ /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ #include <math.h> #define pi 3.14159265358979323846 double distance(double lat1, double lon1, double lat2, double lon2, char unit) { double theta, dist; theta = lon1 - lon2; dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta)); dist = acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; switch(unit) { case 'M': break; case 'K': dist = dist * 1.609344; break; case 'N': dist = dist * 0.8684; break; } return (dist); } /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: This function converts decimal degrees to radians :*/ /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ double deg2rad(double deg) { return (deg * pi / 180); } /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ /*:: This function converts radians to decimal degrees :*/ /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ double rad2deg(double rad) { return (rad * 180 / pi); } -------------------- www.c010depunkk.com ~ the hangout of a web developer
|
|
|
Apr 7 2008, 01:31 AM
Post
#4
|
|
|
Master of the Universe ![]() Posts: 1,298 Joined: 15-February 08 From: London, England |
Thanks a lot, thats very helpful.
-------------------- |
|
|
Apr 7 2008, 03:25 AM
Post
#5
|
|
![]() Rapid Squeezer ![]() Posts: 197 Joined: 14-February 08 From: Willich, Germany |
Ur welcome...
Tell us how you solve this, I'd be interested to know -------------------- www.c010depunkk.com ~ the hangout of a web developer
|
|
|
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
9 | craig | 715 | 14th February 2008 - 11:54 AM Last post by: Simon |
|||
![]() |
12 | gribble | 556 | 19th February 2008 - 05:49 AM Last post by: welshstew |
|||
![]() |
11 | Simon | 293 | 15th February 2008 - 04:06 AM Last post by: Simon |
|||
![]() |
4 | Vanessa | 472 | 23rd April 2008 - 01:28 PM Last post by: karinne |
|||
![]() |
20 | thesealportalteam | 1,207 | 25th February 2008 - 09:53 AM Last post by: thesealportalteam |
|||






Apr 6 2008, 03:22 PM








