# [URGENT] Distance & Time Between 2 Postcodes

Hello Experts,

Has anyone got a working example of how to get the distance (miles) between 2 UK postcodes?

I know of MultiMap which provides directions but i have no idea how to pull selected data from the web page.

http://www.multimap.com/map/aproute.cgi?client=public&lang=&rn=GB&input_rt=aproute_pan&startcountry=GB&startrd=&starttown=&startpc=dl1+4su&endcountry=GB&endrd=&endtown=&endpc=dh3+2sa&qs=q&starttime=15%3A05

Is there any way i could just get the 'Estimated Duration' and 'Total Distance' from the ROUTE INFORMATION panel at the right hand side of the page, at the top?

If there is it would be ideal. Thanks.

Dave
LVL 6
###### Who is Participating?

Commented:
Oops one syntax error:

just change the following line
> return strEstimatedDuration & "@" & strTotalDistance
to
GetMultiMapInfo = strEstimatedDuration & "@" & strTotalDistance
0

Commented:
If you're talking about "as the crow flies" distance, you could use the free geocoding resources on the Web to get lat/long points for each postcode.  Then you can calculate the distance using the technique described here:  http://geocoder.us/blog/2006/04/21/calculating-distances/
0

Author Commented:
No, sorry, its more for tracking how far our vehicles will be driving :o)
0

Commented:
try this:
<%
Response.Buffer = True

response.Write GetMultiMapInfo("http://www.multimap.com/map/aproute.cgi?client=public&lang=&rn=GB&input_rt=aproute_pan&startcountry=GB&startrd=&starttown=&startpc=dl1+4su&endcountry=GB&endrd=&endtown=&endpc=dh3+2sa&qs=q&starttime=15%3A05")

function GetMultiMapInfo(MultimapURL)
dim strPage, xml, lngStart, lngEnd, strEstimatedDuration, strTotalDistance, strStOffset, strEndOffset
if MultimapURL="" then
exit function
end if

Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", MultimapURL, False
xml.Send
strPage = xml.responseText
Set xml = Nothing

strStOffset = "<dt>Estimated duration:</dt>"
strEndOffset = "</dd>"
lngStart = instr(100,strPage, strStOffset) + len(strStOffset) + 1
lngEnd = instr(lngStart,strPage,strEndOffset)
strEstimatedDuration = replace(mid(strPage, lngStart, lngEnd - lngStart),"<dd>","")

strStOffset = "<dt>Total distance:</dt>"
strEndOffset = "</dd>"
lngStart = instr(lngEnd,strPage, strStOffset) + len(strStOffset) + 1
lngEnd = instr(lngStart,strPage,strEndOffset)
strTotalDistance = replace(mid(strPage, lngStart, lngEnd - lngStart),"<dd>","")

return strEstimatedDuration & "@" & strTotalDistance
end function
%>

And the output will be: 0 hours, 40 minutes@32.7 miles (52.6 km)

I hope this would be useful for you.
0

Author Commented:
Works perfect... thank you :o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.