문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top