如何用 2 种不同的颜色绘制 2 条线:每组线都有设置的坐标。集合没有连接

How do I draw 2 lines with 2 different colors: each set of lines has set Coordinates. the Sets are not connected

如何画两条不相连的线,两条线必须有不同的颜色,两条线有来自四组坐标的点。所以每条线都有自己的一组坐标。使用 Objective C iOS 7.

二号塔现在不画画

 if ([deg2 isEqual: @""] ) {
    //nil

}else{
    //not nil

    //Tower Two
    //draw line from lat2/long2 to finalLat2/finalLong2
    CLLocationCoordinate2D coordinateArray2[2];
    coordinateArray2[0] = CLLocationCoordinate2DMake([lat2 doubleValue], [long2 doubleValue]); //tower two
    coordinateArray2[1] = CLLocationCoordinate2DMake(finalLat2, finalLong2);
    self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray2 count:2];

}

一号塔绘制

   //tower one
  // [self.mapview setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
    //draw line from lat1/long1 to finalLat1/finalLong1
    CLLocationCoordinate2D coordinateArray[2];
    coordinateArray[0] = CLLocationCoordinate2DMake([lat1 doubleValue], [long1     doubleValue]); //tower one
    coordinateArray[1] = CLLocationCoordinate2DMake(finalLat1, finalLong1);



    self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
    [self.mapview setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
    [self.mapview addOverlay:self.routeLine];
}

这是一号塔获取线条颜色的方式

//Tower One Line
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
    if(overlay == self.routeLine)
    {
        if(nil == self.routeLineView)
        {
            self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
            self.routeLineView.fillColor = [UIColor greenColor];
            self.routeLineView.strokeColor = [UIColor greenColor];
            self.routeLineView.lineWidth = 5;
        }
        return self.routeLineView;
    }
    return nil;
}

我只需要在 .h 文件中添加

@property (nonatomic, retain) MKPolyline *routeLine1; //ORGINAL LINE
@property (nonatomic, retain) MKPolylineView *routeLineView1; //ORGINAL LINE

@property (nonatomic, retain) MKPolyline *routeLine2; //ADDED LINE
@property (nonatomic, retain) MKPolylineView *routeLineView2; //ADDED LINE

这在.m

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if(overlay == self.routeLine1)
{
    if(nil == self.routeLineView1)
    {
        self.routeLineView1 = [[MKPolylineView alloc] initWithPolyline:self.routeLine1];
        self.routeLineView1.fillColor = [UIColor greenColor];
        self.routeLineView1.strokeColor = [UIColor greenColor];
        self.routeLineView1.lineWidth = 5;

    }

    return self.routeLineView1;
}


if(overlay == self.routeLine2)
{
    if(nil == self.routeLineView2)
    {
        self.routeLineView2 = [[MKPolylineView alloc] initWithPolyline:self.routeLine2];
        self.routeLineView2.fillColor = [UIColor orangeColor];
        self.routeLineView2.strokeColor = [UIColor orangeColor];
        self.routeLineView2.lineWidth = 5;

    }

    return self.routeLineView2;
}

return nil;

}