How to: Display MKOverlay on MKMapView

为君一笑 提交于 2019-12-05 07:00:40

Make sure to set mapView's delegate to the view controller instance( perhaps File's owner in this case).

In interface builder, right-click on the map view, drag from hollowed circle at the right of delegate, to the File's Owner icon at the Placeholder section in the pane on the left.

For storyboard, connect to the View Controller icon instead of File's Owner.

Probably you killing aView in - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay by return nil; Try to add else before.

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MKPolygon class]])
    {
        MKPolygonView* aView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];

        aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
        aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];
        aView.lineWidth = 3;

        return aView;
    }
    else return nil;
} 

Did you solve your problem? Just drag from the circle beside delegate (in your screen shot) to the circle which is the name of the class.. there is a setting in the inspector that would allow you to display where you are also..? You made need to centre the map in say viewDidLoad so it displays over Colorado..

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