How to distinguish two MKPolyline's in viewForOverlay:

我怕爱的太早我们不能终老 提交于 2019-12-04 14:34:51

MKPolyline inherits from MKShape which has a settable title (and subtitle) property which you can use to tell them apart.

This answer has an example of how to use it with MKPolygon objects.

If title and subtitle are not sufficient for your requirements, then you can subclass as Mundi commented.

MKPolyLine is a subclass of UIView. Thus I would go with tags. This also makes it quite easy to refer to the lines when you need them (with viewWithTag) could be subclassed to add a tag-like identifier.

i'm using mkcircle as an example

  MKCircle *circle = [MKCircle circleWithCenterCoordinate:currentPoint radius:radius];
    [circle setTitle:@"circle1"];
    [map addOverlay:circle];


- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
    NSLog(@"overlay %@",overlay);

    if ([[overlay title] isEqualToString:@"circle1"]){

    circleView = [[MKCircleView alloc] initWithOverlay:overlay];
    //circleView.strokeColor = [UIColor redColor];
    circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.3];

    return circleView;
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!