I am trying to understand DistanceMatrix API. When I do this on browser:
I get the duration_in_traffic.
{
"destination_addresses" : [
"17 Orchard Rd, Bagumbayan, Quezon City, 1109 Metro Manila, Philippines"
],
"origin_addresses" : [ "74 C. Benitez St, Quezon City, Metro Manila, Philippines" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "8.5 km",
"value" : 8470
},
"duration" : {
"text" : "23 mins",
"value" : 1406
},
"duration_in_traffic" : {
"text" : "35 mins",
"value" : 2112
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
But when I have it in golang using maps API
I do not get the duration_in_traffic and returns only null
r := &maps.DistanceMatrixRequest{
Language: *language,
DepartureTime: "now",
ArrivalTime: *arrivalTime,
}
Below is result
{
"origin_addresses": [
"74 C. Benitez St, Quezon City, Metro Manila, Philippines"
],
"destination_addresses": [
"17 Orchard Rd, Bagumbayan, Quezon City, 1109 Metro Manila, Philippines"
],
"rows": [
{
"elements": [
{
"status": "OK",
"distance": {
"text": "8.5 km",
"value": 8470
},
"duration": {
"value": 1406,
"text": "23m26s"
},
"duration_in_traffic": null
}
]
}
]
}
Anything I am doing wrong?
EDIT:
r := &maps.DistanceMatrixRequest{
Origins: strings.Split(origins, "|"),
Destinations: strings.Split(destinations, "|"),
Language: "en",
DepartureTime: "now",
Mode: maps.TravelModeDriving,
Units: maps.UnitsMetric,
}
resp, err := client.DistanceMatrix(context.Background(), r)
if err != nil {
return c.JSON(http.StatusBadRequest, err)
}
return c.JSON(http.StatusOK, resp)