Nokia Here地图错误时,建立一个路线与许多坐标
Nokia Here maps error when building a route with many coordinates
例如,我有500个路线坐标,我想建立路线,使用这个坐标从A点到B点
现在我使用下面的代码:
router = new nokia.maps.routing.Manager();
// The function onRouteCalculated will be called when a route was calculated
var onRouteCalculated = function (observedRouter, key, value) {
if (value == "finished") {
var routes = observedRouter.getRoutes(),
container = new nokia.maps.map.Container(),
route = routes[0],
waypoints = route.waypoints,
i, length = waypoints.length;
// Add route polyline to the container
container.objects.add(new nokia.maps.map.Polyline(route.shape, {
pen : new nokia.maps.util.Pen({
lineWidth: 5,
strokeColor: "#AB7A8C"
})
}));
// Add container to the map
map.objects.add(container);
// Iterate through all waypoints and add them to the container
for (i = 0; i < length; i++) {
//
container.objects.add(new nokia.maps.map.StandardMarker(waypoints[i].originalPosition, {
text: String.fromCharCode(65 + i) //65 is a char code for "A"
}));
}
//Zoom to the bounding box of the route
map.zoomTo(container.getBoundingBox(), false, "default");
} else if (value == "failed") {
alert("The routing request failed.");
}
};
/* We create on observer on router's "state" property so the above created
* onRouteCalculated we be called once the route is calculated
*/
router.addObserver("state", onRouteCalculated);
// Create waypoints
var waypoints = new nokia.maps.routing.WaypointParameterList();
$.each(routesArr, function (key, value){
nokia.maps.geo.Coordinate(parseFloat(value[1]), parseFloat(value[0])));
var Coords = value.split(' ');
console.log(Coords);
waypoints.addCoordinate(new nokia.maps.geo.Coordinate(parseFloat(Coords[1]), parseFloat(Coords[0])));
})
console.log(waypoints);
/* Properties such as type, transportModes, options, trafficMode can be
* specified as second parameter in performing the routing request.
*
* See for the mode options the "nokia.maps.routing.Mode" section in the developer's guide
*/
var modes = [{
type: "fastest",
transportModes: ["car"],
trafficMode: "disabled",
options: ""
}];
// Trigger route calculation after the map emmits the "displayready" event
map.addListener("displayready", function () {
router.calculateRoute(waypoints, modes);
}, false);
但在调试器中出现错误:
["32.0966977626384", "49.4231563713862"] functions.js:142
["32.0968187973202", "49.4231926231174"] functions.js:142
["32.0967591181696", "49.4231632026373"] functions.js:142
["32.0967998542191", "49.4231820200099"] functions.js:142
["32.0968651492448", "49.4232476922212"] functions.js:142
["32.0969191287012", "49.4233110594092"] functions.js:142
["32.0969724376054", "49.4233680982603"] functions.js:142
["32.0970814023466", "49.4234444154887"] functions.js:142
["32.0972258225382", "49.4235442020459"] functions.js:142
["32.0974480267913", "49.4237132650329"] functions.js:142
["32.0977787766904", "49.4239508081688"] functions.js:142
["32.0976077020467", "49.4238198828412"] functions.js:142
["32.0980493445248", "49.4241391076235"] functions.js:142
["32.0982283819766", "49.4242630759714"] functions.js:142
["32.0986557752193", "49.4245636510192"] functions.js:142
["32.0987762231679", "49.424653169745"] functions.js:142
["32.0984075032474", "49.4243849907531"] functions.js:142
["32.0988543425054", "49.4246631442098"] functions.js:142
["32.0988309569956", "49.4246686343564"] functions.js:142
["32.0988922287078", "49.4246461708559"] functions.js:142
["32.0989042148293", "49.4246334722726"] functions.js:142
["32.0989042148293", "49.4246334722726"] functions.js:142
GET http://route.st.nlp.nokia.com/routing/6.2/calculateroute.json?routeattribut…ck=(function()%7Bnokia.maps.net.Request.callbacks%5B4%5D(5,arguments);%7D) 502 (BAD_GATEWAY) base.js:167
Uncaught TypeError: Cannot read property 'error' of undefined
我解决不了这个问题,有人能帮我解决吗?
如果你只是在地图上画一条线,不需要Route
,你需要Polyline:
。
// Set of initial geo coordinates to create the purple polyline
var points = [
new nokia.maps.geo.Coordinate(50.1299, 8.5680),
new nokia.maps.geo.Coordinate(50.0969, 8.4829),
new nokia.maps.geo.Coordinate(50.0819, 8.4856),
new nokia.maps.geo.Coordinate(50.0555, 8.4479)
];
// Transparent purple polyline
var polyline = new nokia.maps.map.Polyline(
points,
{
pen: {
strokeColor: "#22CA",
lineWidth: 5
}
}
);
map.objects.add(polyline);
目前你的样本正试图计算驾驶指令从A到B到C到D ....我怀疑这是不是你想要的你可以定义的中间点的数量是有限的,如果我没记错的话,大约是10个。
您可以使用以下命令zoomTo
路由:
map.zoomTo(polyline.getBoundingBox(), false, "default");
相关文章:
- 使用D3.js和GeoJson在地图上的某些坐标上设置一个小图像
- 如何创建一个谷歌地图地理坐标数组
- JS:给定一个x,y坐标列表,可以找到介于1,1和给定最大值之间的缺失坐标
- 我在 JS 中做错了什么?我需要每个元素的一个坐标,但不是全部
- 如何连续地将拉斐尔画布(包含一些对象)从一个坐标移动到另一个坐标再到其他坐标
- 使用 jQuery offset() 将绝对定位的 DIV 设置为另一个 DIV 的相同 y 坐标
- JS:显示一个无限长的坐标系统(网格)
- 将鼠标坐标从一个窗口大小转换为另一个窗口尺寸
- 创建一个Javascript对象来容纳用户'的地理位置坐标
- 矩形坐标投影到另一个矩形中
- 如何检查鼠标的Y坐标是否大于一个值
- 在html中的屏幕坐标(x,y)处选择一个单词
- 如何将谷歌地理位置的坐标传递给另一个函数
- 如果我有一个lat/lng我假设它在(0,0)那么我如何计算另一个lat/lng对的x, y坐标
- 如何找到如果一个坐标是在一个多边形在猫鼬节点js
- 如何从一个角度找到(x,y)坐标
- 使用jquery,我想把一个图像在另一个基于坐标
- 如何知道一个坐标是在多边形内还是在多边形外?PHP +谷歌地图+ JS
- 如何绘制一个矩形,其坐标存储在mysql数据库中
- 选择一个坐标为(x,y)的元素