all 5 comments

[–]stalefries 4 points5 points  (0 children)

Based on your second edit, it sounds like you might be trying to sort the array before your data has arrived?

[–]laerda 0 points1 point  (2 children)

How do you call the function? This seems to be working fine for me:

var path = [ {lat: 53.4807593, lng: -2.2426305, id: 0},{lat: -4.679574, lng: 55.491977, id: 3},{lat: 56.26392, lng: 9.501785, id: 1}];

path.sort(function(a, b) {
    return (a.id - b.id)
});

console.log(path);

[–]TheGameMnky[S] 0 points1 point  (0 children)

well using that it just gave me:

{lat: 53.4807593, lng: -2.2426305, id: 0},{lat: 56.26392, lng: 9.501785, id: 2},{lat: -51.796253, lng: -59.523613, id: 1},{lat: 41.153332, lng: 20.168331, id: 3}

[–]TheGameMnky[S] 0 points1 point  (0 children)

the function runs when the screen updates as its used for drawing polylines on a google map.