Kodeco Forums

MapKit Tutorial: Overlay Views

Learn how to add satellite and hybrid maps, custom images, annotations, lines, boundaries and circles to the standard map using MapKit Overlay Views.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/425-mapkit-tutorial-overlay-views

Sorry if this is a noob question…any idea why I’m getting the error ‘Return from initializer without initializing all stored properties – self.boundary not initialized’ in the Park class? I had the .map closure in there (even copied and pasted from the tutorial thinking I missed something), and also tried replacing it with a loop like in the original tutorial like this:

let cgPoints = boundaryPoints.map { CGPointFromString($0) }
        var boundaryTmp: [CLLocationCoordinate2D] = []
        for i in 0...cgPoints.count - 1 {
            let j = CLLocationCoordinate2DMake(CLLocationDegrees(cgPoints[i].x), CLLocationDegrees(cgPoints[i].y))
            boundaryTmp.append(j)
        }
        self.boundary = boundaryTmp

Thanks!

@owenb Could you please help with this when you get a chance? Thank you - much appreciated! :]

You probably forgot to give the ivar an initial value…

var boundary: [CLLocationCoordinate2D] = []

1 Like

I agree with lars, be sure boundary is initialized in its declaration, or if you prefer, initialize it in init().

@lars @owenb Thanks guys! What a simple thing I overlooked. Looking forward to finishing this today. Great post!

Did anyone do a technical edit of this posting?

mapView.mapType = MKMapType.init(rawValue: UInt(sender.selectedSegmentIndex)) ?? .standard

You should definitely not be calling .init directly like that at all.

It should be noted that there are some major performance issues that are reflected when using MapKit on the Xcode 9 betas (sims) as seen here. It may be a good call to call this out in the above posting as the region is rarely, if at all, set and animated.

MKOverlayRenderer also inherits from NSObject. It has no direct association to a UIView. I’m not quite sure why the subclass doesn’t indicate this an why it’s referenced as being a UIView child. A renderer != a view.

Should likely remove the ; after break;

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!