I got a button on excel to run a Google Distance Service to Calculate how many miles and the duration of the travelling time is.
When I run the service I get the following response text, I wondering how can I extract just the Status, Distance, Duration from JSON response text and copy into my excel worksheet cells.
the following is the response text I got from the Google Distance service.
{
"destination_addresses" : [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ],
"origin_addresses" : [ "Vancouver, BC, Canada", "Seattle, Washington, États-Unis" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 709 km",
"value" : 1709333
},
"duration" : {
"text" : "3 jours 19 heures",
"value" : 327629
},
"status" : "OK"
},
{
"distance" : {
"text" : "135 km",
"value" : 134569
},
"duration" : {
"text" : "6 heures 22 minutes",
"value" : 22946
},
"status" : "OK"
}
]
Sub Button1_Click()
Dim x As Long, y As Long
Dim htm As Object
Dim wb As Workbook
Dim ws As Worksheet
Dim TxtRng As Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
Set htm = CreateObject("htmlFile")
With CreateObject("msxml2.xmlhttp")
.Open "GET", "https://maps.googleapis.com/maps/api/distancematrix/json?origins=sy3 3jp&destinations=hr3 3ly&mode=driving&language=en-GB&v=3&sensor=fals", False
.send
htm.body.innerhtml = .responseText
Debug.Print .responseText
End With
End Sub