public function containsCoordinate(LatLng $coord, $isCheckVertex = false)
    {
        // Check if the point sits exactly on a vertex
        if ($isCheckVertex == true && $this->isOnVertexOfPolygon($coord) == true) {
            return true; // vertex
        }

        // Check if the point is inside the polygon or on the boundary
        $intersections = 0;
        $paths = ArrayHelper::getValue($this->options, 'paths');
        $vertexCount = count($paths);

        for ($i = 1; $i < $vertexCount; $i++) {
            $vertex1 = $paths[$i - 1];
            $vertex2 = $paths[$i];

            // Check if point is on a latitude polygon boundary
            if ($vertex1->lat == $vertex2->lat &&
                $vertex1->lat == $coord->lat &&
                $coord->lng > min($vertex1->lng, $vertex2->lng) &&
                $coord->lng < max($vertex1->lng, $vertex2->lng)
            ) {
                return true; // boundary
            }

            // Check if point is on a longitude polygon boundary
            if ($coord->lat > min($vertex1->lat, $vertex2->lat) &&
                $coord->lat <= max($vertex1->lat, $vertex2->lat) &&
                $coord->lng <= max($vertex1->lng, $vertex2->lng) &&
                $vertex1->lat != $vertex2->lat
            ) {
                $xinters = $coord->lat - $vertex1->lat;
                $xinters = $xinters * ($vertex2->lng - $vertex1->lng);
                $xinters = $xinters / ($vertex2->lat - $vertex1->lat);
                $xinters = $xinters + $vertex1->lng;

                if ($xinters == $coord->lng) {
                    return true; // boundary
                }
                if ($vertex1->lng == $vertex2->lng || $coord->lng <= $xinters) {
                    $intersections++;
                }
            }
        }

        // If the number of edges we passed through is odd, then it's in the polygon.
        if ($intersections % 2 != 0) {
            return true; // inside
        }
        return false; // outside
    }
public function containsCoordinate(LatLng $coord, $isCheckVertex = false)
    {
        // Check if the point sits exactly on a vertex
        if ($isCheckVertex == true && $this->isOnVertexOfPolygon($coord) == true) {
            return true; // vertex
        }

        // Check if the point is inside the polygon or on the boundary
        $intersections = 0;
        $paths = ArrayHelper::getValue($this->options, 'paths');
        $vertexCount = count($paths);

        for ($i = 1; $i < $vertexCount; $i++) {
            $vertex1 = $paths[$i - 1];
            $vertex2 = $paths[$i];

            // Check if point is on a latitude polygon boundary
            if ($vertex1->lat == $vertex2->lat &&
                $vertex1->lat == $coord->lat &&
                $coord->lng > min($vertex1->lng, $vertex2->lng) &&
                $coord->lng < max($vertex1->lng, $vertex2->lng)
            ) {
                return true; // boundary
            }

            // Check if point is on a longitude polygon boundary
            if ($coord->lat > min($vertex1->lat, $vertex2->lat) &&
                $coord->lat <= max($vertex1->lat, $vertex2->lat) &&
                $coord->lng <= max($vertex1->lng, $vertex2->lng) &&
                $vertex1->lat != $vertex2->lat
            ) {
                $xinters = $coord->lat - $vertex1->lat;
                $xinters = $xinters * ($vertex2->lng - $vertex1->lng);
                $xinters = $xinters / ($vertex2->lat - $vertex1->lat);
                $xinters = $xinters + $vertex1->lng;

                if ($xinters == $coord->lng) {
                    return true; // boundary
                }
                if ($vertex1->lng == $vertex2->lng || $coord->lng <= $xinters) {
                    $intersections++;
                }
            }
        }

        // If the number of edges we passed through is odd, then it's in the polygon.
        if ($intersections % 2 != 0) {
            return true; // inside
        }
        return false; // outside
    }
public function containsCoordinate ( LatLng $ coord , $ isCheckVertex = false ) { // Check if the point sits exactly on a vertex if ( $ isCheckVertex == true && $ this -> isOnVertexOfPolygon ( $ coord ) == true ) { return true ; // vertex } // Check if the point is inside the polygon or on the boundary $ intersections = 0 ; $ paths = ArrayHelper :: getValue ( $ this -> options , 'paths' ) ; $ vertexCount = count ( $ paths ) ; for ( $ i = 1 ; $ i < $ vertexCount ; $ i ++ ) { $ vertex1 = $ paths [ $ i - 1 ] ; $ vertex2 = $ paths [ $ i ] ; // Check if point is on a latitude polygon boundary if ( $ vertex1 -> lat == $ vertex2 -> lat && $ vertex1 -> lat == $ coord -> lat && $ coord -> lng > min ( $ vertex1 -> lng , $ vertex2 -> lng ) && $ coord -> lng < max ( $ vertex1 -> lng , $ vertex2 -> lng ) ) { return true ; // boundary } // Check if point is on a longitude polygon boundary if ( $ coord -> lat > min ( $ vertex1 -> lat , $ vertex2 -> lat ) && $ coord -> lat <= max ( $ vertex1 -> lat , $ vertex2 -> lat ) && $ coord -> lng <= max ( $ vertex1 -> lng , $ vertex2 -> lng ) && $ vertex1 -> lat != $ vertex2 -> lat ) { $ xinters = $ coord -> lat - $ vertex1 -> lat ; $ xinters = $ xinters * ( $ vertex2 -> lng - $ vertex1 -> lng ) ; $ xinters = $ xinters / ( $ vertex2 -> lat - $ vertex1 -> lat ) ; $ xinters = $ xinters + $ vertex1 -> lng ; if ( $ xinters == $ coord -> lng ) { return true ; // boundary } if ( $ vertex1 -> lng == $ vertex2 -> lng || $ coord -> lng <= $ xinters ) { $ intersections ++ ; } } } // If the number of edges we passed through is odd, then it's in the polygon. if ( $ intersections % 2 != 0 ) { return true ; // inside } return false ; // outside }
Returns true if coordinate is within polygon

@param LatLng $coord
@param bool $isCheckVertex Check if the point sits exactly on one of the vertices? Default is false.

@return boolean true if the coordinate is inside polygon
Returns true if coordinate is within polygon