Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am very much new to leaflet.

I have multiple markers plotted on my map in leaflet.

now I have to draw line between two markers when I select them.

Can any one help in doing this.

share|improve this question
How you can select two circles at a time in leaflet?? – Sunil Mar 4 '13 at 13:12

So it seems to me all you have to do is take the two markers you have selected and grab their latlngs and add them to the polyline.

var latlngs = Array();

//Get latlng from first marker

//Get latlng from first marker

//You can just keep adding markers

//From documentation
// create a red polyline from an arrays of LatLng points
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);

// zoom the map to the polyline


In case you are looking for a way to also get the selected markers. You will need to probably listen to the click event of each marker and add the markers to an array that contains your selected markers. You will just need to limit that array to two entries. This is not an optimal solution but should get you there and will allow you to easily extend if you want more than two markers.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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