isGeoPointInPolygon method

bool isGeoPointInPolygon(
  1. LatLng position
)

Implementation

bool isGeoPointInPolygon(LatLng position) {
  bool isInPolygon = false;
  List<LatLng> points = first.toLatLng();

  for (int i = 0, j = points.length - 1; i < points.length; j = i++) {
    bool latCheck =
        (points[i].latitude > position.latitude) !=
        (points[j].latitude > position.latitude);
    double intersectLongitude =
        (points[j].longitude - points[i].longitude) *
            (position.latitude - points[i].latitude) /
            (points[j].latitude - points[i].latitude) +
        points[i].longitude;
    if (latCheck && position.longitude < intersectLongitude) {
      isInPolygon = !isInPolygon;
    }
  }
  return isInPolygon;
}