0

I use CoreData to save/load locations with a title and description. The loading/saving works properly. The latitude and longitudes are saved as NSNumbers. The annotation used in the below code is correct and has data in it.

Somehow, the pin is not being placed on the map. Why?

func setAnnotationPinOnMap(annotation : NSManagedObject)
{

    var subject: AnyObject? = annotation.valueForKey("subject")
    var desc: AnyObject? = annotation.valueForKey("desc")
    var langitude: AnyObject? = annotation.valueForKey("langitude")
    var longitude: AnyObject? = annotation.valueForKey("longitude")
    println(annotation);
    let pin = MKPointAnnotation()

    let location = CLLocationCoordinate2D(
        latitude: langitude as CLLocationDegrees,
        longitude: longitude as CLLocationDegrees
    )
    println(location.longitude, location.latitude)
    pin.setCoordinate(location)
    pin.title = subject as String!
    pin.subtitle = desc as String!
    mapView.addAnnotation(pin)
}
Kraishan
  • 443
  • 5
  • 14
  • 38
  • possible duplicate of [MapKit Annotations not showing up on map](http://stackoverflow.com/questions/20460541/mapkit-annotations-not-showing-up-on-map) – Anthony Kong Oct 30 '14 at 12:43
  • 1
    I clearly stated the language here is Swift, not objective C. – Kraishan Oct 30 '14 at 13:48
  • What do the `println`s print exactly? What are the coordinates? The viewForAnnotation delegate method is _not required_ to show annotations but if you _have_ implemented it, please add that code to the question. –  Oct 30 '14 at 14:34
  • The println(annotation) shows the data in annotation. This is all correct. The location.longitude gives something like 52.xxxxxx and the latitude 4.xxxx so that works too I guess? I do not have a viewForAnnotation delegate. – Kraishan Oct 30 '14 at 16:25
  • 1
    The coordinates longitude 52 and latitude 4 are in the Indian Ocean off the coast of Somalia. Is that where you are expecting the annotation? If you actually meant to put it somewhere in Amsterdam, then the longitude should be 4 and the latitude should be 52 (**swap the values**). –  Oct 30 '14 at 16:54
  • Indeed. Somehow I swapped the values in the process. Thanks! – Kraishan Oct 30 '14 at 18:26

0 Answers0