matthew.armitage
Board Regular
- Joined
- Nov 23, 2009
- Messages
- 72
Hi All
Does anyone have a working method for calculating the the distance between UK postcodes?
I have a method that has worked in the past, that I actually found on Mr Excel, but it no longer works
Help appreciated
Thanks
Matt
Does anyone have a working method for calculating the the distance between UK postcodes?
I have a method that has worked in the past, that I actually found on Mr Excel, but it no longer works
VBA Code:
Function G_DISTANCE(Origin As String, Destination As String) As Double
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
G_DISTANCE = 0
On Error GoTo exitRoute
Origin = Replace(Origin, " ", "%20")
Destination = Replace(Destination, " ", "%20")
Set myRequest = New XMLHTTP60
myRequest.Open "GET", "http://maps.googleapis.com/maps/api/directions/xml?origin=" _
& Origin & "&destination=" & Destination & "&sensor=false", False
myRequest.send
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")
If Not distanceNode Is Nothing Then G_DISTANCE = distanceNode.Text / 1000
exitRoute:
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function
Help appreciated
Thanks
Matt