How can I detect if an MKPolyline intersects itself? I tried researching this but only found problems that has two or more lines. How can I detect if I only have one line/one stroke? I want to detect it after the user releases the touch.
I currently have this code in touchEnded function.
            CGPoint location = [touch locationInView:self.mapView];
            CLLocationCoordinate2D coordinate = [self.mapView convertPoint:location toCoordinateFromView:self.mapView];
            [self.coordinates addObject:[NSValue valueWithMKCoordinate:coordinate]];
            NSInteger numberOfPoints = [self.coordinates count];
            if(numberOfPoints > 2)
            {
                [self setLineLength:[self getLengthArea]];
                if([self lineLength] < 401)
                {
                    if (numberOfPoints > 2)
                    {
                        CLLocationCoordinate2D points[numberOfPoints];
                        for (NSInteger i = 0; i < numberOfPoints; i++) {
                            points[i] = [self.coordinates[i] MKCoordinateValue];
                        }
                        [self.mapView addOverlay:[MKPolyline polylineWithCoordinates:points count:numberOfPoints]];
                    }
                    PCAnnotation *ann = [[PCAnnotation alloc] init];
                    [ann setCoordinate:coordinate];
                    ann.title = @"End";
                    [self.mapView addAnnotation:ann];
                }
                else
                {
                    NSArray *overlayItems = [self.mapView overlays];
                    NSArray *annotations = [self.mapView annotations];
                    [self.mapView removeOverlays:overlayItems];
                    [self.mapView removeAnnotations:annotations];
                }
            }