[URGENT] Distance & Time Between 2 Postcodes

Posted on 2006-06-02
Last Modified: 2011-09-20
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.

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.

Question by:davecestria
    LVL 9

    Expert Comment

    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:
    LVL 6

    Author Comment

    No, sorry, its more for tracking how far our vehicles will be driving :o)
    LVL 8

    Expert Comment

    try this:
          Response.Buffer = True
          response.Write GetMultiMapInfo("")
          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
                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.
    LVL 8

    Accepted Solution

    Oops one syntax error:

    just change the following line
    > return strEstimatedDuration & "@" & strTotalDistance
    GetMultiMapInfo = strEstimatedDuration & "@" & strTotalDistance
    LVL 6

    Author Comment

    Works perfect... thank you :o)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now