douhuan1950 2016-11-09 22:05
浏览 23

Golang Google Maps API到达

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.

  • 写回答

1条回答 默认 最新

  • dsfdsfds521521 2016-11-10 02:35
    关注

    It would appear this is a limitation of the Google Maps API, not the Go client. For those who see this question in the future, experiment with different combinations of parameters (leaving different ones out) until it works.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算