0

Using XCode v7.0 Beta 4

I attempt to add a visible pin to that map via map.addAnnotation(myareahere) as you can see here:

    let myareahere = CLLocationCoordinate2DMake(51.5072, -0.1275)

    let annotation = MKPointAnnotation()
    annotation.coordinate = myareahere
    annotation.title = "Name of My Area"
    annotation.subtitle = "Sleep Here"

    map.addAnnotation(myareahere)

This is all of course contained within the viewDidLoad function. The error I'm given on the last line (map.addAnnotation(myareahere)) is "Cannot invoke 'addAnnotation' with an argument of list type (CLLocationCoordinates2D)". This is perplexing to me for I do not know what else I would use.

Blumie
  • 45
  • 1
  • 5
  • 1
    Have you read the documentation for `MKMapView` and the `addAnnotation` method? https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapView_Class/#//apple_ref/occ/instm/MKMapView/addAnnotation: It clearly shows that you need to supply an `MKAnnotation` instance. Your code creates the MKAnnotation and then does nothing with it! – Paulw11 Aug 06 '15 at 23:06

2 Answers2

1

The error is telling you that you're invoking addAnnotation(_:) with the wrong argument type. You're passing a CLLocationCoordinate2D to the method, you mean to pass annotation (your MKPointAnnotation instance).

Stuart
  • 36,683
  • 19
  • 101
  • 139
1

Seems like a simple typo. Try

let annotation = MKPointAnnotation()
annotation.coordinate = myareahere
annotation.title = "Name of My Area"
annotation.subtitle = "Sleep Here"

map.addAnnotation(annotation)

.

eik
  • 2,104
  • 12
  • 15