title: Using leaflet mapping api, how do you determine which point in a polyline was clicked on?
body: <p>I'm using the Leaflet mapping API. I would like to determine which point in a polyline has been clicked on. The polyline is one that I have rendered using the Directions services from MapQuest Open.</p>
  
  <p>The relevant code is:</p>
  
  <pre><code>for ( var i = 0; i &lt; latlngs.length; i++ )
     {
  
     // the equals method uses a small fudge factor to decide if the two 
     // points are the same.
  
     if ( latlng.equals( latlngs[ i ] ))
        {
        return i;
        }
     }
  </code></pre>
  
  <p>.equals() is supposed to compare points with a fudge factor. When I click on the polyline I get an event with lat/lngs like:</p>
  
  <pre><code>'38.83966582989183','-77.0083075761795' 
  </code></pre>
  
  <p>My lat/lngs in the polyline are of less precision as in:</p>
  
  <pre><code>'38.841289','-77.008842' 
  </code></pre>
  
  <p>So as I loop through looking for a match <code>equals()</code> never returns true. Clearly, the click event is firing, so leaflet knows I've clicked the polyline, but there doesn't seem to be a clean way of getting the actual offset of the latlng that was clicked on.</p>
  
  <p>I'm considering just reducing the precision returned from the mouse click, but that doesn't "feel" like the right solution.</p>
  
  <p>Any help/pointers would be greatly appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>Setting <code>L.LatLng.MAX_MARGIN</code> to <code>1.0E-3</code> seems to work but that seems like a very coarse margin.</p>