我想检查一个点是否位于特定的多边形内。多边形为: polygon= [ [-73.89632720118, 40.8515320489962], [-73.8964878416508, 40.8512476593594], [-73.8968799791431, 40.851375925454], [-73.8967188588015, 40.851660158514], [-73.89632720118, 40.8515320489962] ]我要检查的要点是: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]如何判断这些点中的每一个是否都位于该多边形内?以下算法无效。我不知道为什么pt[lat,long]function isPointInPoly(poly, pt){ for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) ((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || (poly[j][1] <= pt[1] && pt[1] < poly[i].y)) && (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) && (c = !c); return c;}我不想使用第三方解决方案,例如google maps API或https://github.com/mattwilliamson/Google-Maps-Point-in-Polygon这样的第三方解决方案。我的尝试在这里:http : //jsfiddle.net/nvNNF/2/
添加回答
举报
0/150
提交
取消