有没有办法将nokia.maps.routing.Manager与替代路线一起使用?
因为如果我在结果请求URL中添加“alternatives = 2”,我得到的结果不仅仅是1。
原:
in response json: response.route contains 1 element
修改(看看最后 - “& alternatives = 2”):
in response json: response.route contains 3 elements
所以有一种方法。我只是不知道如何使用nokia.maps.routing.Manager
到达那里答案 0 :(得分:2)
nokia.maps.routing.Manager(基于7.2路由)不支持备选方案作为参数。要将此参数传递给路由,您需要使用对后端路由服务器的JSONP调用:
startRouting = function()
{
var routeUrl = ["http://route.nlp.nokia.com/routing/7.2/calculateroute.json?",
"app_id=" + app_id + "&",
"app_code=" + app_code + "&",
"waypoint0=" + startLat + ","+ startLng + "&",
"waypoint1="+ destLat + "," + destLng + "&",
"instructionformat=text" + "&",
"jsonAttributes=33" + "&",
"mode=fastest;car;traffic:disabled&",
"routeattributes=sh",
"&alternatives=2",
"&jsoncallback=routingcallback"].join("");
script = document.createElement("script");
script.src = routeUrl;
document.body.appendChild(script);
}
var strokeColor = ["#7a24db", "#85db24","#8f0404", "#fdf700"];
routingcallback = function(data)
{
var routes = data.response.route;
for(var i = 0; i < routes.length; i++)
{
var coords = routes[i].shape;
var shape = nokia.maps.geo.Shape.fromLatLngArray(coords, false);
var curColor = strokeColor[i];
if(routes.length == 1)
curColor = strokeColor[3];
var line = new nokia.maps.map.Polyline(shape, { pen: { strokeColor: curColor, lineWidth: 4 } });
display.objects.add(line);
display.zoomTo(line.getBoundingBox(), false, "default");
}
}