I've written some code in Golang to get directions from one place to another using the Google Maps API. According to the Godoc, both the DepartureTime
and ArrivalTime
parameters are optional. However, if I try to make any request without specifying the departure time, the code fails, giving me the following error message: INVALID_REQUEST - Invalid request. Missing the 'departure_time' parameter
. Here's the relevant code:
client, err := maps.NewClient(maps.WithAPIKey(apiKey), maps.WithRateLimit(2))
check(err, "new maps client")
r := &maps.DirectionsRequest{
Origin: origin,
Destination: destination,
ArrivalTime: arrivalTime,
Alternatives: alternatives,
Mode: maps.TravelModeDriving,
}
lookupTrafficModel(trafficModel, r)
if avoid != "" {
lookupAvoidPoints(avoid, r)
}
//THIS LINE IS WHERE THE ERROR IS THROWN
routes, waypoints, err := client.Directions(context.Background(), r)
check(err, "getting directions")
fmt.Println(waypoints)
fmt.Println(routes)
Note that if I comment out the ArrivalTime
parameter and instead use DepartureTime: "now",
(as per the Godoc), this code works as expected.