首页 > 解决方案 > 如何在反应中检查标记位于多个多边形中

问题描述

这段代码只需要一个多边形我想要一些可以带多个多边形的东西来检查 lat lng 是否位于其中一个!有什么解决办法吗?

componentDidMount() {
  const polygon = [
    { lat: 3.1336599385978805, lng: 101.31866455078125 },
    { lat: 3.3091633559540123, lng: 101.66198730468757 },
    { lat: 3.091150714460597,  lng: 101.92977905273438 },
    { lat: 3.1336599385978805, lng: 101.31866455078125 } // last point has to be same as first point
  ];

  let point = {
    lat: 2.951269758090068,
    lng: 101.964111328125
  };

  GeoFencing.containsLocation(point, polygon)
    .then(() => console.log('point is within polygon'))
    .catch(() => console.log('point is NOT within polygon'))
}

标签: javascriptnode.jsreactjsgoogle-mapsmaps

解决方案


推荐阅读