November 14, 2014 at 3:28 pm
Hi,
I want to be able to calculate the Distance between two UK Postcodes.
So there will two parameters being past through
@StartPostcode
@EndPostcode
So when passing in the @StartPostcode = L1 and @EndPostcode = M1 then it will return the distinace in Miles which would be 38.8 based on Distance by Road as per the example from the below website:
Has anyone does something similar? And where would I need to download the table that will hold the postcode longitude/latitude information if required?
Thanks
November 14, 2014 at 3:43 pm
i don't think UK postcodes are an exact measurable science i could be wrong. They are assigned on a street level and one long street will usually have many postcodes
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
November 14, 2014 at 3:46 pm
I only want the short post code not bothered about the full post code, the website is only doing the short post code so it won't be as many lookups to calculate I am presuming.
November 14, 2014 at 5:01 pm
If you want to code it yourself, you need to work with spatial data. There might be some way to get all the data instead of collecting it, but I can't tell where to find it.
This can help you to start with spatial data: http://technet.microsoft.com/en-us/library/bb933876(v=sql.105).aspx
November 15, 2014 at 1:37 pm
Hi,
So I have found this website that has a user defined function
http://www.hexcentral.com/articles/postcodes-distances.htm">
http://www.hexcentral.com/articles/postcodes-distances.htm
CREATE FUNCTION dbo.GetDistance
(@e1 float, @e2 float, @n1 float, @n2 float)
RETURNS float
AS
BEGIN
RETURN sqrt(square(@e1 - @e2) + square(@n1 - @n2))
END
I am not getting the correct miles when running the function for the postcodes of L1 to M1, this is the longitue latitude i got from the net which i am guessing is what needs to be passed through?
Select dbo.GetDistance(53.402051,-2.979837,53.478484,-2.23557)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply