title: How to draw a path between two nodes using Leaflet
body: <p>I have a set of lat and long points which form a route from source to destination. I have used polyline method of Leaflet to draw the path between the source to destination, but it gives a scrambled path.</p>
  
  <pre><code>      var firstpolyline = new L.polyline(latlong, {
        color: 'red',
        weight: 3,
        opacity: 0.5,
        smoothFactor: 1
  
        });
        firstpolyline.addTo(mym[![enter image description here][1]][1]ap);
  </code></pre>
  
  <p>The <strong>latlong</strong> in the above code is an array of latitude and longitude points. But it gives a scrambled output like this:</p>
  
  <p><a href="https://i.stack.imgur.com/OKzr2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OKzr2.jpg" alt="polyline forming scrambled output"></a>imgur.com/aZrGa.jpg</p>
  
  <p>But the latlong points form a single correct path from source to destination. I have been using polyLine. What mistake am I doing? Should I use some other methods of Leaflet?</p>
  
  <h2>Edit after @ivansanchez comment</h2>
  
  <p>The latlong arrays are of type L.LatLng(x,y) where L is the Leaflet object. Here is a snippet:</p>
  
  <p><a href="https://i.stack.imgur.com/VNpDf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VNpDf.png" alt="enter image description here"></a></p>