Google Maps API for Time and Distance Data (Access / VBA)

I have an application in which it would be very useful to be able to receive directly from Google maps the time and miles (miles of driving) between two addresses. I have plowed many websites and documents and are completely devoid of how to do this.

Has anyone made a successful connection to the Google Maps API using the Microsoft Approach and time and distance information? If they can use the code they used.

I am trying to set up a driver planning system for a volunteer group of drivers (driving for people with medical appointments who cannot drive, cannot afford a taxi and cannot afford cars!).

Any help would be appreciated

John Baker

+3
source share
1 answer

Here is the code you want to make. Understand that Google has some requirements or restrictions for using the API. You must use the results obtained here on Google Map. Please read our usage restrictions here: https://developers.google.com/maps/documentation/directions/

Please note that this requires a reference to "Microsoft XML, v6.0" unless you change the code to use late binding.

Dim sXMLURL As String
sXMLURL = "http://maps.googleapis.com/maps/api/directions/xml?origin=NY,+NY&destination=Los+Angeles,+CA&sensor=false"

Dim objXMLHTTP As MSXML2.ServerXMLHTTP
Set objXMLHTTP = New MSXML2.ServerXMLHTTP

With objXMLHTTP
    .Open "GET", sXMLURL, False
    .setRequestHeader "Content-Type", "application/x-www-form-URLEncoded"
    .Send
End With

'Debug.Print objXMLHTTP.ResponseText

Dim domResponse as DOMDocument60
Set domResponse = New DOMDocument60
domResponse.loadXML objXMLHTTP.ResponseText
Dim ixnStatus
Set ixnStatus = domResponse.selectSingleNode("//status")

If ixnStatus.Text = "OK" Then
    Dim ixnDistance, ixnDuration
    Set ixnDistance = domResponse.selectSingleNode("/DirectionsResponse/route/leg/distance/text")
    Set ixnDuration = domResponse.selectSingleNode("/DirectionsResponse/route/leg/duration/text")

    Debug.Print "Distance: " & ixnDistance.Text 'Miles
    Debug.Print "Duration: " & ixnDuration.Text 'Days Hours Minutes
End If

Set domResponse = Nothing
Set objXMLHTTP = Nothing

XML JSON, VBA JSON, . , , VBJSON, , JSON. , XML "" ( ), , Access VBA.

+8

All Articles