Google Road Api SnapToRoad golang [英] Google Road Api SnapToRoad golang

查看:411
本文介绍了Google Road Api SnapToRoad golang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行谷歌的 snaptoroad api。但我没有得到任何输出。我正在使用golang来实现。我的代码如下:

I was trying to implement google's snaptoroad api. But I am not getting any output. I am using golang for the implementation. My Code is as follows:

mapClient, err := maps.NewClient(maps.WithAPIKey(GoogleApiServerKey))
if err != nil{
    log.Println(err)
}

//Input
latlng := maps.LatLng{}
path := []maps.LatLng{}
latlng.Lat = 9.7162348
latlng.Lng = 76.6702793
path = append(path, latlng)
latlng.Lat = 9.7162400
latlng.Lng = 76.715195
path = append(path, latlng)
latlng.Lat = 9.7162410
latlng.Lng = 76.7759261
path = append(path, latlng)

inputRequest := &maps.SnapToRoadRequest{
    Path: path,
}

outputResponse, err := mapClient.SnapToRoad(context.Background(), inputRequest)

fmt.Println(outputResponse)
pretty.Println(outputResponse)

此代码产生的输出是

The Output this code produces are

&{[]}
&maps.SnapToRoadResponse{}

返回空白输出。任何人都请指出我在这里犯的错误?提前致谢。

Blank output is returned. Anyone please point out the mistake I made here? Thanks in advance.

推荐答案

您的代码很好,但看起来您的API密钥未被激活。
请访问 googleAPI信息中心
以启用它。

Your code is fine, but It seems that your API Key is not activated. Please visit googleAPI dashboard to enable it.

您可以随时查看它的运作情况:
https://roads.googleapis.com/v1/snapToRoads?path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796&key=YOUR_API_KEY

You can always check it working: https://roads.googleapis.com/v1/snapToRoads?path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796&key=YOUR_API_KEY

输出结果为:

the output would be:

{
  "snappedPoints": [
    {
      "location": {
        "latitude": 60.170877918672588,
        "longitude": 24.942699821922421
      },
      "originalIndex": 0,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    },
    {
      "location": {
        "latitude": 60.170876898776406,
        "longitude": 24.942699912064775
      },
      "originalIndex": 1,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    },
    {
      "location": {
        "latitude": 60.170874902634374,
        "longitude": 24.942700088491474
      },
      "originalIndex": 2,
      "placeId": "ChIJNX9BrM0LkkYRIM-cQg265e8"
    }
  ]
}

这篇关于Google Road Api SnapToRoad golang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆