Closed Thread
Results 1 to 43 of 43

Google Maps Driving Times

Hybrid View

thegooser123 Google Maps Driving Times 02-05-2011, 11:17 AM
pike Re: Google Maps Driving Times 02-06-2011, 04:23 AM
thegooser123 Re: Google Maps Driving Times 02-06-2011, 01:18 PM
DonkeyOte Re: Google Maps Driving Times 02-06-2011, 02:11 PM
thegooser123 Re: Google Maps Driving Times 02-06-2011, 03:57 PM
DonkeyOte Re: Google Maps Driving Times 02-06-2011, 04:01 PM
thegooser123 Re: Google Maps Driving Times 02-06-2011, 04:30 PM
DonkeyOte Re: Google Maps Driving Times 02-06-2011, 05:40 PM
thegooser123 Re: Google Maps Driving Times 02-06-2011, 06:38 PM
DonkeyOte Re: Google Maps Driving Times 02-06-2011, 06:44 PM
sellenwood Re: Google Maps Driving Times 02-07-2011, 06:37 PM
pike Re: Google Maps Driving Times 02-07-2011, 06:51 PM
thegooser123 Re: Google Maps Driving Times 02-10-2011, 08:00 AM
TMS Re: Google Maps Driving Times 02-10-2011, 08:59 AM
DonkeyOte Re: Google Maps Driving Times 02-10-2011, 09:16 AM
TMS Re: Google Maps Driving Times 02-10-2011, 09:38 AM
DonkeyOte Re: Google Maps Driving Times 02-10-2011, 09:45 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 06:02 AM
Domski Re: Google Maps Driving Times 04-13-2011, 06:17 AM
TMS Re: Google Maps Driving Times 04-13-2011, 06:16 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 06:18 AM
Domski Re: Google Maps Driving Times 04-13-2011, 06:30 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 06:40 AM
Domski Re: Google Maps Driving Times 04-13-2011, 08:24 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 08:33 AM
Domski Re: Google Maps Driving Times 04-13-2011, 08:47 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 08:50 AM
Domski Re: Google Maps Driving Times 04-13-2011, 08:57 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 09:08 AM
Domski Re: Google Maps Driving Times 04-13-2011, 10:19 AM
thegooser123 Re: Google Maps Driving Times 04-13-2011, 04:00 PM
sk80rb0i SOLVED - Re: Google Maps... 07-28-2011, 01:26 PM
ChemistB Re: Google Maps Driving Times 07-28-2011, 01:40 PM
sk80rb0i Re: Google Maps Driving Times 07-28-2011, 01:44 PM
TMS Re: Google Maps Driving Times 07-28-2011, 02:00 PM
sk80rb0i Re: Google Maps Driving Times 07-28-2011, 02:12 PM
TMS Re: Google Maps Driving Times 07-28-2011, 02:23 PM
adam2804 Re: Google Maps Driving Times 09-28-2011, 09:42 AM
thegooser123 Re: Google Maps Driving Times 09-28-2011, 09:56 AM
Domski Re: Google Maps Driving Times 09-28-2011, 10:07 AM
Khirsah17 Re: Google Maps Driving Times 11-30-2011, 03:03 PM
pauldaddyadams Re: Google Maps Driving Times 11-30-2011, 05:03 PM
pike Re: Google Maps Driving Times 11-30-2011, 06:36 PM
  1. #1
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Google Maps Driving Times

    Made a couple of changes to this function that's called which seems to make it work now:

    Public Function parseGoog(strSearch As String, strHTML As String) As String
        strSearch = "," & strSearch & ":'"
        If InStr(1, strHTML, strSearch) = 0 Then
            parseGoog = "Not Found"
            Exit Function
        Else
            parseGoog = Mid(strHTML, InStr(1, strHTML, strSearch) + Len(strSearch))
            parseGoog = Mid(parseGoog, 1, InStr(1, parseGoog, "'") - 1)
        End If
    End Function

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  2. #2
    Registered User
    Join Date
    08-30-2010
    Location
    Cornwall, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Google Maps Driving Times

    Quote Originally Posted by Domski View Post
    Made a couple of changes to this function that's called which seems to make it work now:

    Public Function parseGoog(strSearch As String, strHTML As String) As String
        strSearch = "," & strSearch & ":'"
        If InStr(1, strHTML, strSearch) = 0 Then
            parseGoog = "Not Found"
            Exit Function
        Else
            parseGoog = Mid(strHTML, InStr(1, strHTML, strSearch) + Len(strSearch))
            parseGoog = Mid(parseGoog, 1, InStr(1, parseGoog, "'") - 1)
        End If
    End Function

    Dom
    This is working perfectly for the distances in miles, however the driving times are all messed up.

    Any ideas?

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Google Maps Driving Times

    What did it used to return for them? I never tried it to be honest.

    Dom

  4. #4
    Registered User
    Join Date
    08-30-2010
    Location
    Cornwall, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Google Maps Driving Times

    Quote Originally Posted by thegooser123 View Post
    This is working perfectly for the distances in miles, however the driving times are all messed up.

    Any ideas?
    =GetGoogDistanceTime(A1,B1,"time")
    I think its giving me the mileage though.

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Google Maps Driving Times

    I meant what sort of value did it used to return? Time in hours/mins/seconds?

    Dom

  6. #6
    Registered User
    Join Date
    08-30-2010
    Location
    Cornwall, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Google Maps Driving Times

    Quote Originally Posted by Domski View Post
    I meant what sort of value did it used to return? Time in hours/mins/seconds?

    Dom
    Sorry Dom...

    it used to return time formatted as hh:mm.

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Google Maps Driving Times

    Maybe:

    Public Function getGoogDistanceTime(rngSAdd As Range, rngEAdd As Range, Optional strReturn As String = "distance") As Variant
        Dim sURL As String
        Dim BodyTxt As String
        Dim vUnits As Variant
        Dim dblTemp As Double
        Dim bUnit As Byte
        sURL = "http://maps.google.com/maps?f=d&source=s_d"
            sURL = sURL & "&saddr=" & Replace(rngSAdd(1).Value, " ", "+")
            sURL = sURL & "&daddr=" & Replace(rngEAdd(1).Value, " ", "+")
            sURL = sURL & "&hl=en"
        Debug.Print sURL
        BodyTxt = getHTML(sURL)
        If InStr(1, BodyTxt, strReturn, vbTextCompare) = 0 Then
            getGoogDistanceTime = "Error"
        Else
            getGoogDistanceTime = parseGoog(strReturn, BodyTxt)
            If LCase(strReturn) Like ",time*" Then
                vUnits = Split(getGoogDistanceTime)
                For bUnit = LBound(vUnits) To UBound(vUnits) - 1 Step 2
                    dblTemp = dblTemp + _
                            Val(vUnits(bUnit)) / Choose(InStr(1, "hms", Left(vUnits(bUnit + 1), 1), vbTextCompare), 24, 1440, 86400)
                Next bUnit
                getGoogDistanceTime = dblTemp
            Else
                getGoogDistanceTime = Val(getGoogDistanceTime)
            End If
        End If
    End Function
    
    Public Function getHTML(strURL As String) As String
        Dim oXH As Object
        Set oXH = CreateObject("msxml2.xmlhttp")
        With oXH
            .Open "get", strURL, False
            .send
            getHTML = .responseText
        End With
        Set oXH = Nothing
    End Function
    
    Public Function parseGoog(strSearch As String, strHTML As String) As String
        strSearch = "," & strSearch & ":'"
        If InStr(1, strHTML, strSearch) = 0 Then
            parseGoog = "Not Found"
            Exit Function
        Else
            parseGoog = Mid(strHTML, InStr(1, strHTML, strSearch) + Len(strSearch))
            parseGoog = Mid(parseGoog, 1, InStr(1, parseGoog, "'") - 1)
        End If
    End Function

    Dom

  8. #8
    Registered User
    Join Date
    08-30-2010
    Location
    Cornwall, UK
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Google Maps Driving Times

    works a charm mate.

    Thank you so much for all your help

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1