9
如何檢測MKPolyline是否相交?我試圖研究這個,但只發現有兩行或更多行的問題。如何檢測我是否只有一行/一行?我想在用戶釋放觸摸後檢測它。MKPolyline檢測自相交線目標C
我現在的觸摸功能有這段代碼。
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];
}
}