0

我如何绘制两条不相互连接的线,两条线必须有不同的颜色,两条线有来自四组坐标的点。所以每条线都有自己的一组坐标。使用目标 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 如何获得线条颜色

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

1 回答 1

0

我只需要添加 .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;

}
于 2015-10-22T22:28:14.117 回答