未添加到mapView的注释

时间:2014-10-30 12:26:05

标签: xcode swift annotations mkmapview

我使用CoreData来保存/加载带有标题和描述的位置。加载/保存工作正常。纬度和经度保存为NSNumbers。以下代码中使用的注释是正确的,并且包含数据。

不知何故,引脚没有放在地图上。为什么呢?

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)
}

0 个答案:

没有答案
相关问题