Nokia Here地图错误时,建立一个路线与许多坐标

Nokia Here maps error when building a route with many coordinates

本文关键字:一个 坐标 许多 错误 地图 Here 建立 Nokia      更新时间:2023-09-26

例如,我有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");