在地图上绘制2条折线

时间:2016-02-18 09:11:00

标签: ios objective-c mapkit

我在地图上的2个点之间绘制折线,但是如何绘制2条不同的折线呢?这就是我想要做的事情:

 CLLocationCoordinate2D myCoordinate;

    for (int i=0; i<station.count; i++) {
        if ([station[i] isEqualToString:cell.textLabel.text]) {
            foo= [localization[indexPath.row+1] componentsSeparatedByString: @","];
            break;

        }

    }

    myCoordinate.latitude=[foo[0] floatValue];
    myCoordinate.longitude=[foo[1] floatValue];
    CLLocationCoordinate2D center = myCoordinate;
    [self.mapView setCenterCoordinate:center animated:YES];
    self.mapView.zoomEnabled=YES;
    MKCoordinateRegion region;
    region.center=center;   // location
    MKCoordinateSpan span;
    span.latitudeDelta=0.002;               //  0.001 to 120
    span.longitudeDelta=0.002;
    region.span=span;
    [self.mapView setRegion:region animated:YES];



- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {

    if([overlay class] == MKPolyline.class)
    {
        MKOverlayView* overlayView = nil;
       MKPolyline* polyline = (MKPolyline *)overlay;
        MKPolylineView  * routeLineView = [[MKPolylineView alloc] initWithPolyline:polyline];
        if([polyline.title isEqualToString:@"typeA"])
        {
            routeLineView.fillColor = [UIColor redColor];
            routeLineView.strokeColor = [UIColor redColor];
        } else {
            routeLineView.fillColor = [UIColor blueColor];
            routeLineView.strokeColor = [UIColor blueColor];

        }
        routeLineView.lineWidth = 3;
        routeLineView.lineCap = kCGLineCapSquare;
        overlayView = routeLineView;
        return overlayView;
    } else {
        return nil;
    }
}

但它没有用。我有一条折线。我们将不胜感激。

0 个答案:

没有答案