title: Check if Point Is Inside A Polygon
body: <p>I want to check if a point lies within a specific polygon. The polygon is:</p>
  <pre><code> polygon=   [ [-73.89632720118, 40.8515320489962],
                [-73.8964878416508, 40.8512476593594],
                [-73.8968799791431, 40.851375925454],
                [-73.8967188588015, 40.851660158514],
                [-73.89632720118, 40.8515320489962] ]
            
  </code></pre>
  <p>The points I want to check are:</p>
  <pre><code>1 = [40.8515320489962,-73.89632720118]
  2 = [40.8512476593594,-73.8964878416508]
  3 = [40.851375925454,-73.8968799791431]
  4 = [40.851660158514,-73.8967188588015]
  5 = [40.8515320489962,-73.89632720118]
  </code></pre>
  <p>How can I tell if each of these points lies within this polygon?</p>
  <p>The algorithm below does not work. I don't know why.</p>
  <pre><code>pt[lat,long]
  
  function isPointInPoly(poly, pt){
      for(var c = false, i = -1, l = poly.length, j = l - 1; ++i &lt; l; j = i)
          ((poly[i][1] &lt;= pt[1] &amp;&amp; pt[1] &lt; poly[j][1]) || (poly[j][1] &lt;= pt[1] &amp;&amp; pt[1] &lt; poly[i][1]))
          &amp;&amp; (pt[0] &lt; (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
          &amp;&amp; (c = !c);
      return c;
  }
  </code></pre>
  <p>I don't want to use a third party solution such as google maps API or this one <a href="https://github.com/mattwilliamson/Google-Maps-Point-in-Polygon" rel="noreferrer">https://github.com/mattwilliamson/Google-Maps-Point-in-Polygon</a>.</p>
  <p>My attempt is here:
  <a href="http://jsfiddle.net/nvNNF/2/" rel="noreferrer">http://jsfiddle.net/nvNNF/2/</a></p>