Question

Here is my code:

$.each(data, function (i, val) {

    salesmanTrackPoints[val.id] = new Array();

    var coords = new nokia.maps.geo.Coordinate(parseFloat(val.latitude), parseFloat(val.longitude));

    salesmanTrackPoints[val.id] = new nokia.maps.map.Polyline(coords, {
        polyline: {
            pen: {
                strokeColor: "#00F8",
                lineWidth: 5
            }
        },
        arrows: true
    });

    map.objects.add(salesmanTrackPoints[val.id]);

});

Above code is not working. Please help me if what is wrong.

Was it helpful?

Solution

To create the Polyline, you need to add the array of coordinates inside the loop, and then outside of the loop you can add a single mapobject to the Display e.g.:

 var coords = [],
  salesmanTrackPoints;

// Loop to add all the coordinates to an array
$.each(data, function (i, val) {
  coords.push(parseFloat(val.latitude));
  coords.push(parseFloat(val.longitude));
});

// Now create the Polyline
salesmanTrackPoints = new nokia.maps.map.Polyline(coords, {
  pen: {
    strokeColor: "#22CA",
    lineWidth: 5
  },
  arrows: true
});
map.objects.add(salesmanTrackPoints);

Of course this may need to be altered depending upon the structure of your data. It is important to note that Polyline can take an Array of Coordinates or an Array of Numbers (as individual lat, longs) as you can see from the API Documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top