Trouble with overlay using MKPolyline & MKPolylineView

笑着哭i 提交于 2019-12-06 11:01:32

I ended up fixing my problem by implementing the MKOverlay Protocol method:

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

like so:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];

    if(overlay.title == @"Blue Route")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-A")
    {
        aView.lineWidth = 10.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-B")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    return aView;

}

Where each overlay was created elsewhere in my model.

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