Print Page | Close Window

Distance calculating

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: General Discussion
Forum Description: General discussion and chat on any topic.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12407
Printed Date: 01 April 2026 at 5:14pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Distance calculating
Posted By: Mattblack
Subject: Distance calculating
Date Posted: 01 November 2004 at 4:15pm

hi all,

I desperately need to find out how I can obtain a database or other file containing all UK post codes and some other info (Maybe grid ref) so i can calculate distance between 2 postcodes.

Any ideas where i can find something like that?  Or does anyone know any other way of doing it???

Thanks again




Replies:
Posted By: michael
Date Posted: 01 November 2004 at 5:35pm
Must not have searched to good eh? Here is a link where you can download something http://www.brainstorm.co.uk/uk_post_code_search.htm I did that some time ago for the US with a free DB from the US Census Office and once you got the formula down, it is easy. If the databases have LAT and LON coordinates for the zip's its easy, otherwise you need to find a lookup for that. Formula can get complex depending how accurate you want it because if you have LAT/LON you still need to calculate the curviture between those points.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mattblack
Date Posted: 02 November 2004 at 2:57am

Hi Mate, thanks for that.

Erm, about that cash, lol.  They will be cutting my net off soon so i will have to dis....



Posted By: Mattblack
Date Posted: 02 November 2004 at 2:58am

PS: Check out: http://www.jibble.org/ukpostcodes/postcodes.zip - http://www.jibble.org/ukpostcodes/postcodes.zip

oh im cut of....



Posted By: Mattblack
Date Posted: 02 November 2004 at 3:47am
wots the difference then between the grid ref and the lat/lon ref?  Which should be used?


Posted By: michael
Date Posted: 02 November 2004 at 9:31am
not shure about grid ref, never worked with it. Lat Lon worked fine for me.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mattblack
Date Posted: 02 November 2004 at 12:34pm

confused now, cant work it out.

Take this post code example....

postcode x y latitude longitude
AB10 392900 804900 57.135 -2.117

How many miles is each grid ref?  Or each 1 point on the lat/long scale???

Can anyone explain the grid ref and what each of the numbers mean? Do u have to break it down into 2 3-number sections?  If now, how far would, for example, 010000 be in miles?

Thankies



Posted By: michael
Date Posted: 02 November 2004 at 1:14pm
Well, like I said I don't know what Grid Ref is but it is simple to calculate somewhat accurate with lat Lon using http://www.meridianworlddata.com/Distance-Calculation.asp - formulas

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mattblack
Date Posted: 02 November 2004 at 4:44pm

excellent, think ive got it!

try my example/test.... http://www.rochdaleoffroad.co.uk/pcdistance.asp - www.rochdaleoffroad.co.uk/pcdistance.asp

Lookup to far away point in autoroute, for example TR19 and KW1, should be 588 miles.

Below is the script for the whole page....

<% if NOT request("calc")="" then
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("******")
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT * FROM tblPC WHERE pc ='" & request("pc1") & "'"
rs.Open sql, conn

do until rs.EOF
  for each entry in rs.Fields
x1=rs("lon")
y1=rs("lat")
     next
  rs.MoveNext
loop
  rs.close
  conn.close

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("/_private/postcodes.mdb")
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT * FROM tblPC WHERE pc ='" & request("pc2") & "'"
rs.Open sql, conn

do until rs.EOF
  for each entry in rs.Fields
x2=rs("lon")
y2=rs("lat")
     next
  rs.MoveNext
loop
  rs.close
  conn.close


xdif = 69.1 * (y2 - y1)
ydif = 69.1 * (x2 - x1) * cos(y1/57.3)
miles=SQR(xdif *xdif +ydif *ydif )


response.write "x1= " & x1& "<BR>"
response.write "y1= " & y1& "<BR>"
response.write "x2= " & x2& "<BR>"
response.write "y2= " & y2& "<BR>"

response.write "xdif = " & xdif & "<BR>"
response.write "ydif = " & ydif & "<BR>"

 

response.write "<P>" & miles & " miles" & "<hr>"
end if
%>
<form method="POST" action="pcdistance.asp">
<p>&nbsp;</p>
<p>Enter first part of post codes (e.g, OL11 for OL11 3RF)</p>
  <p>From postcode: <input type="text" name="pc1" size="4"><br>
  To postcode: <input type="text" name="pc2" size="4"><br>
  <input type="submit" value="Calculate mileage (Crows path)" name="calc"></p>
</form>



Posted By: Mart
Date Posted: 05 November 2004 at 4:48pm
If OL11 is your postcode you live 24.8394441363593 miles away from me


Posted By: Mattblack
Date Posted: 05 November 2004 at 6:26pm

oh bloody hell, im moving!

:-)

Where r u? Im in Rochdale



Posted By: dpyers
Date Posted: 05 November 2004 at 7:40pm
You can run, but you can't hide <evil laugh>

-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: Mart
Date Posted: 06 November 2004 at 7:05am
Originally posted by Mattblack Mattblack wrote:

oh bloody hell, im moving!

:-)

Where r u? Im in Rochdale

Thats about right, I live in Macclesfield.



Posted By: barryhunter
Date Posted: 19 November 2004 at 4:51pm

I have a file containing more accurate grid refs if its any use. Going to RH19 1 accuracy, (so can diffienticate between RH19 1 and RH19 2)

As to Grid Refs they are in meter units, east and north from a point off the Sillily Isles. Using Pythagoras on these units you get a exact measurement in meters  which can be easily converted to miles (rather than the one on lat/long which you approximate to miles).

Also Grid Refs are based on a flat grid so you don't have to worry about curvature of the earth, to work out the distance between points.

Having said that it depends on the accuray you require.

Barry




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net