containsLocation static method

bool containsLocation(
  1. LatLng point,
  2. dynamic polygon
)

判断点是否在多边形内

Implementation

static bool containsLocation(LatLng point, dynamic polygon) {
  if (polygon is List) {
    for (final poly in polygon) {
      if (poly is List) {
        List<double> p = [];
        for (final e in poly) {
          final v = num.tryParse(e.toString())?.toDouble();
          if (v != null) {
            p.add(v);
          }
        }
        final len = (p.length / 2).floor();
        final ply = List.generate(len, (index) => index).map((e) => LatLng(p[2 * e + 1], p[2 * e])).toList();
        final status = PolygonUtil.containsLocation(point, ply, true);
        if (status) return true;
      }
    }
  }
  return false;
}