PDA

View Full Version : postcodes and miles


KevinG
09-24-2002, 11:45 PM
does anyone know how i can do this:

this is a car website - http://www.autotrader.co.uk/ when users want to search for a car it requests there postcode as part of the search criteria - the results page then shows how many miles they are away from the each vehicle.

I have all the uk postcodes but i don't know how to get the mileage information from one postcode to another?

any ideas anyone?

bcarl314
09-25-2002, 01:50 PM
Well, a down a dirty way would be to do this. Goto a mapping website (ie yahoo maps, mapquest, etc) and type in the zip codes you've got. Take a look at the map, it should give you Logitude and latitude information for each zip code (or if you're feeling really lucky you can try google for a list) Now take this info and make a database with the following info.

TABLE zips,
FIELDS (ZIPCODE, LONG, LAT)

remember, if the longitude and latitude are in H:M:S format, you'll need to convert to decimal (1H = 60M = 3600S)

From there, you can use the distance formula you remember from algebra to calculate the distance.

given 2 points (x, y) and (a, b) the distance between them is

square_root((x-a)^2+(y-b)^2)).

Now, this will give you a distance in terms of latitude and longitude. You'll then need to convert this to miles or km. I'm assuming that your in the UK, and about 45 degrees north. This means that every degree of seperation (or the result of your distance formula) is about 50 miles.

That should give you a good estimate +/- 10% for distance.

KevinG
09-25-2002, 04:22 PM
thanks for your help bcarl314.

i found the whole caboodle on this site http://www.afd.co.uk/internet.htm although its nearly £2,000 :(

brothercake
09-25-2002, 05:15 PM
The Post Office also sell a database of postcodes/towns etc. the cost is similar to the one you found.

bcarl314
09-25-2002, 06:20 PM
I would have to beleive this information is in the public domain. If nothing else go and get a really good road map (about $50) that has the latitude and logitude info and put it in yourself. $2000 seems to be way too much money for the information you need.

mordred
09-25-2002, 06:53 PM
There are similar packages for this type of information here in Germany, and the price is also more than you typically spend on a pub evening... I guess the information about the coordinates realy is public domain, but you pay for the work that was done collecting and sorting this data. And depending on how fine graned the location in a zipcode can be (here in Germany it boils down to parts of streets in big cities), it would take an awful long time to enter this data into a database yourself.

just my 0.02 €

brothercake
09-25-2002, 11:58 PM
I'd be inclined to agree - cost your own time to enter all that data manually. I guess it depends on the level of detail you need; you can get printed postcode-directories from a library, so it's feasible that such a thing may exist in the public domain in electronic form. In fact a library might be a good palce to look.

KevinG
09-26-2002, 08:23 AM
It looks like i am going to have to buy it as it would take forever to work out the mileage between all the post codes in the uk. at least i know i'm getting a product with everything i need. the two sites i'm working on that require this postcode data are huge projects. one is a national property site the other a national car buy/sell site. I'm also supposed to be doing speedcameras.com.

bcarl314
09-26-2002, 11:35 AM
Ahh, but once you assemble the data set, you can charge $2000 for it! :D

PS: You don't need to work out the milage for each postal code combination, you just need each code's Geographic (Lat/Long) information. Let the math do the work for you in a php script!