【问题标题】:Calculate routes via GET - Polyline incorrect通过 GET 计算路线 - 折线不正确
【发布时间】:2022-02-22 21:56:47
【问题描述】:

我正在测试路由 API(https://developer.here.com/documentation/routing-api/api-reference-swagger.html),除了折线之外,一切似乎都按预期工作。

在这里我分享我的服务调用 curl --location --request GET 'https://router.hereapi.com/v8/routes?transportMode=car&origin=3.4844257,-76.5256287&destination=3.478483,-76.517984&routingMode=fast&return=elevation,polyline,actions,instructions,summary&apiKey=1234'

作为响应的一部分,我们有下一个字段:

"polyline": "B2Fkt10Grm4-xE8yTU4mBnBnG8pBAzP0tBAjD4IA_E8LAvMokBT3IkXTzF8QTnG8QTvMsiBTrJjDA3_BjXoB_sB_OAriB3NAzKjDAnLsTAnLkhBnBzKsdA_J8fTnLkcT3DwHAvC8GArJoQAnL8QA7LsTA7V0jBT_M8UA",

如您所知,折线字段已编码。 根据文档,我继续使用以下建议的库/代码对其进行解码:

https://github.com/heremaps/flexible-polyline/tree/master/java

解码字段的结果不正确。返回的点列表 (Lat,Long,Elevation) 与正确的位置不匹配。在示例中,坐标来自哥伦比亚,解码后的结果返回大西洋中部的点列表。

此外,为了放弃库问题,我正在使用其他解码器检查解码折线:

结果是一样的。

所以,问题似乎出在 HereAPI 方面(API 路由 v8)

有什么想法吗?也许我以不正确的方式调用 API

【问题讨论】:

    标签: rest routes here-api polyline


    【解决方案1】:

    https://github.com/heremaps/flexible-polyline/tree/master/java 上的解码器工作正常,请使用您的编码字符串进行编码:

    private void testSOLatLngDecoding() {
            List<LatLngZ> computed = decode("B2Fkt10Grm4-xE8yTU4mBnBnG8pBAzP0tBAjD4IA_E8LAvMokBT3IkXTzF8QTnG8QTvMsiBTrJjDA3_BjXoB_sB_OAriB3NAzKjDAnLsTAnLkhBnBzKsdA_J8fTnLkcT3DwHAvC8GArJoQAnL8QA7LsTA7V0jBT_M8UA");
            List<String> seqCrds = new ArrayList<>();
            for (int i = 0; i < computed.size(); ++i) {
                LatLngZ c = computed.get(i);
                List<String> crds = new ArrayList<>();
                crds.add(String.valueOf(c.lat));
                crds.add(String.valueOf(c.lng));
                crds.add(String.valueOf(c.z));
                seqCrds.add(String.join(",", crds));
                //assertEquals(computed.get(i), pairs.get(i));
            }
            System.out.println(String.join(",", seqCrds));
        }
    

    我们在https://demo.support.here.com/examples/v3.1/enc_dec_flexible_polyline 上有一个 JavaScript 工具“编码/解码到/从灵活折线”

    请看结果:

    请仔细检查您这边的代码。

    【讨论】:

      【解决方案2】:

      我建议从您在问题中发布的获取请求中删除您的 API 密钥。

      使用您提供的折线被解码为以下内容,位于哥伦比亚。因此,我认为您需要检查您正在使用的解码器和/或正在输入的内容。

      Index Lat Lon Elev
      0 3.48437 -76.52567 1003
      1 3.48438 -76.52505 1001
      2 3.48428 -76.52438 1001
      3 3.48403 -76.52365 1001
      4 3.48398 -76.52351 1001
      5 3.4839 -76.52332 1001
      6 3.4837 -76.52274 1000
      7 3.48356 -76.52237 999
      8 3.48347 -76.5221 998
      9 3.48337 -76.52183 997
      10 3.48317 -76.52128 996
      11 3.48302 -76.52133 996
      12 3.482 -76.5217 998
      13 3.48128 -76.52194 998
      14 3.48073 -76.52216 998
      15 3.48056 -76.52221 998
      16 3.48038 -76.5219 998
      17 3.4802 -76.52137 996
      18 3.48003 -76.5209 996
      19 3.47987 -76.52039 995
      20 3.47969 -76.51994 994
      21 3.47963 -76.51982 994
      22 3.47959 -76.51971 994
      23 3.47944 -76.51945 994
      24 3.47926 -76.51918 994
      25 3.47907 -76.51887 994
      26 3.47872 -76.5183 993
      27 3.478512 -76.517966 993

      【讨论】:

        猜你喜欢
        • 2015-08-12
        • 1970-01-01
        • 2016-04-04
        • 1970-01-01
        • 2019-09-06
        • 2019-02-14
        • 2017-03-19
        • 1970-01-01
        • 2021-12-11
        相关资源
        最近更新 更多