微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Discover / Autosuggest 和 calculateroute API 不会返回从同一点 a 到同一点 b 的相同距离

如何解决Discover / Autosuggest 和 calculateroute API 不会返回从同一点 a 到同一点 b 的相同距离

我一直在使用 Here Maps API,在测试 API 时,我注意到使用发现和自动建议 API 从 A 点到 B 点的距离结果与计算路由 API 给出的结果不同 这是一个例子

这是自动建议 API 返回的内容 https://autosuggest.search.hereapi.com/v1/autosuggest?at=34.7505979,10.71047164&limit=5&lang=en&q=faculté de medecine&apiKey="Your_API_Key"

{
        "title": "Faculté de Médecine","id": "here:pds:place:788jx7ps-886689ec55920a84c15752902c00f8e9","resultType": "place","address": {
            "label": "Faculté de Médecine,Avenue Majida Boulila,Sfax,Tunisia"
        },"position": {
            "lat": 34.73924,"lng": 10.75122
        },"access": [
            {
                "lat": 34.73924,"lng": 10.75122
            }
        ],"distance": 3932,"categories": [
            {
                "id": "800-8200-0173","name": "Higher Education","primary": true
            }
        ],"references": [
            {
                "supplier": {
                    "id": "core"
                },"id": "1126185297"
            }
        ],"highlights": {
            "title": [
                {
                    "start": 0,"end": 19
                }
            ],"address": {
                "label": [
                    {
                        "start": 0,"end": 19
                    }
                ]
            }
        }
    },

如您所见,此 API 返回距离 = 3932

发现 API 也一样: https://discover.search.hereapi.com/v1/discover?at=34.7505979,10.71047164&limit=5&q=faculte de medecine&apiKey="Your_API_KEY" 它返回这个结果:

{
        "title": "كلية الطب (Faculté de Médecine)","address": {
            "label": "كلية الطب,شارع ماجدة بو ليلى,صفاقس,تونس","countryCode": "TUN","countryName": "تونس","county": "صفاقس","city": "صفاقس","district": "صفاقس المدينة","street": "شارع ماجدة بو ليلى"
        },"name": "تعليم عالي","id": "1126185297"
            }
        ]
    },

距离也是3932

而在使用计算路线 API 时: https://route.api.here.com/routing/7.2/calculateroute.json?app_id="Your_APP_ID"&app_code="Your_APP_CODE"&waypoint0=geo!34.7505979,10.75122&mode=fastest;car;traffic:enabled&lang=fr

它回来了

"summary": {
                "distance": 4800,"trafficTime": 692,"baseTime": 692,"flags": [
                    "builtUpArea"
                ],"text": "The trip takes <span class=\"length\">4.8 km</span> and <span class=\"time\">12 mins</span>.","travelTime": 692,"_type": "RouteSummaryType"
            }
        }

所以这里的距离是 4800

所以,我的问题是,这是一种错误,还是我遗漏了什么

谢谢。

解决方法

Autosuggest API 请求响应中的'distance' 不考虑任何路由和流量参数。所以距离计算为A点到B点的距离。

详情:https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-autosuggest-brief.html

但是如果在计算路线的响应中是“距离”,它会考虑运输方式、交通状况以及其他路由参数。

https://route.api.here.com/routing/7.2/calculateroute.json?app_id="Your_APP_ID"&app_code="Your_APP_CODE"&waypoint0=geo!34.7505979,10.75122&mode=fastest;car;traffic:enabled&lang=fr

详情:https://developer.here.com/documentation/routing-api/8.22.2/dev_guide/topics/send-request.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。