1

I am trying to give a polyline a new set of co ordinates from a server. When trying to use the .setLatLngs method to redraw the new line with updated co ordinates i get the error "Uncaught TypeError: a.setLatLngs is not a function". Am I using this method incorrectly? If so how do i use this method?

var a = new L.LatLng(0,0),
    b = new L.LatLng(0,0);


var polyline = new L.Polyline([a, b]).addTo(mymap);

//this is inside an ajax query
    a.setLatLngs([latA1,lonA1]);
    b.setLatLngs([latA6,lonA6]);


//latA1, lonA1 are new points for a point on the line
//latA6, lonA6 are new points for a point on the line
1

I figured why the setLatLngs method wasnt working for me. I was passing in coordinates to the method rather than passing in the polyline itself.

//working code

 polyline.setLatLngs([ [latA1, lonA1] ,[latA5,lonA5] ]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.