0

I have a custom MkAnnotation that has a title, subtitle, and extra information associated with it for use on an map view. I am passing this information to another UIViewController. However there seems to be some issue with my coordinate that I have allocated for the pin. The error is highlighted in the setting information of pin below on the line of code "var bridge17pin = MyAnnotation()".

   override func viewDidLoad() {
    super.viewDidLoad()

    //for users location
    myLocMgr.desiredAccuracy = kCLLocationAccuracyBest
    myLocMgr.requestWhenInUseAuthorization()
    myLocMgr.startUpdatingLocation()
    myLocMgr.delegate = self
    mapView.delegate = self



 //coordinate for pin
 var bridge17 = CLLocationCoordinate2DMake(53.346061, -6.227379)


       //custom MKAnnotation
       class MyAnnotation: NSObject, MKAnnotation {
        @objc var coordinate: CLLocationCoordinate2D
        var EXTRA_INFORMATION: String?
        var title: String?

        init(coordinate: CLLocationCoordinate2D) {
           self.coordinate = coordinate
        }
    }



    //setting information of pin
    var bridge17pin = MyAnnotation()
    bridge17pin.coordinate = bridge17
    bridge17pin.title = "The bridge"
    bridge17pin.subtitle = "hello this is the bridge"
    bridge17pin.EXTRA_INFORMATION = "this was built in 2010"
    mapView.addAnnotation(bridge17pin)
      }

1 Answers1

0

Because you have to send the coordinate while you are instantiating. So in the code replace

var bridge17pin = MyAnnotation()

with

var bridge17pin = MyAnnotation(coordinate: bridge17)

And for that subTitle see this link

Community
  • 1
  • 1
Naveen Kumar H S
  • 1,304
  • 16
  • 30