我是MapHere的新手,我看到在REST API方面,我可以指定waipoint,但是我不能使用JavaScript,我尝试了一些参数,例如“ via”,但只承认了一点:
var routingParameters = {
'routingMode': 'fast',
'transportMode': 'car',
// The start point of the route:
'origin': '36.8414197,-2.4628135',
'via': '37.9923795,-1.1305431',
// The end point of the route:
'destination': '40.4167047,-3.7035825',
// Include the route shape in the response
'return': 'polyline'
};
我在javascript网站的主页上看到了一个示例,但是我不能使用航点:
var router = platform.getRoutingService(),
routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
routeattributes: 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action',
waypoint0: '52.5160,13.3779', // Brandenburg Gate
waypoint1: '52.5206,13.3862' // Friedrichstraße Railway Station
};
引发以下错误:
{"title":"Malformed request","status":400,"code":"E605001","cause":"Error while parsing request: 'origin' parameter is required\n","action":"","correlationId":"1c7bd525-b8af-4989-83a9-ab07f26a8c33"}
那么,如何发送使用航路点的请求?
编辑
我看到了问题,当.js创建url编码第二个&via=
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654%26via%3D51.2234%2C9.1123&return=polyline
如果我解码&
并且=
正常工作
https://router.hereapi.com/v8/routes?xnlp=CL_JSMv3.1.18.1&apikey=***&routingMode=fast&transportMode=car&origin=50.1120%2C8.6834&destination=52.5309%2C13.3846&via=50.1234%2C8.7654&via=51.2234%2C9.1123&return=polyline
答案 0 :(得分:3)
JavaScript API尚不支持(从库版本3.1.18.1开始)传递多个航路点,这意味着将点数组传递给via
参数。关于这种缺乏支持的最佳选择是直接使用Routing REST API:
https://router.hereapi.com/v8/routes?
origin=52.550464,13.384223
&transportMode=car
&destination=52.477545,13.447395
&via=52.529791,13.401389
&via=52.513079,13.424392
&via=52.487581,13.425079
&apikey={YOUR_API_KEY}