• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

[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
0
davecestria
Asked:
davecestria
  • 2
  • 2
1 Solution
 
HappyFunBallCommented:
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
 
davecestriaAuthor Commented:
No, sorry, its more for tracking how far our vehicles will be driving :o)
0
 
sankarbhaCommented:
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
 
sankarbhaCommented:
Oops one syntax error:

just change the following line
> return strEstimatedDuration & "@" & strTotalDistance
to
GetMultiMapInfo = strEstimatedDuration & "@" & strTotalDistance
0
 
davecestriaAuthor Commented:
Works perfect... thank you :o)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now