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

时间:2015-10-22 19:02:37

标签: mkpolyline cllocationcoordinate2d

如何绘制两条彼此未连接的线,两条线必须具有不同的颜色,两条线具有四组坐标的点。所以每一行都有自己的坐标集。使用Objective C iOS 7。

Tower Two现在不画画

 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确实画了

   //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获取线条颜色的方式

//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;
}

1 个答案:

答案 0 :(得分:0)

我只需要添加.h文件

def PascalTriangle(rows):

    ptriangle = [[1], [1, 1]]
    if rows == 1:
        return ptriangle[0]
    else:
        for rownumber in range(2, rows):
            ptriangle.append([1]*rownumber)
            for number in range(1, rownumber):
                ptriangle[rownumber][number] = (ptriangle[rownumber-1][number-1]+ptriangle[rownumber-1][number])                           
                ptriangle[rownumber].append(1)
        return ptriangle

def PrintPascalTriangle(ptriangle):

    largest_element = ptriangle[-1][len(ptriangle[-1]) // 2]
    element_width = len(str(largest_element))
    def format_row(row):
        return ' '.join([str(element).center(element_width) for element in row])
    triangle_width = len(format_row(ptriangle[-1]))
    for row in ptriangle:
        print(format_row(row).center(triangle_width))

rows = input('Enter the number of rows in Pascal`s Triangle: ')
assert (rows > 0),"Number of rows should be greater than zero"
PrintPascalTriangle(PascalTriangle(rows)) 

这在.m

@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