如何从iOS库中获取照片并在地图上显示(mapkit)

时间:2016-01-02 16:35:14

标签: swift mapkit photos

我需要从库中获取图片,并在map上添加可预订的预览。 我已经设法添加了引脚,但我无法获取相关的照片并显示它们。

这是我用照片框架编写的代码

    let resultCollections = PHAssetCollection.fetchAssetCollectionsWithType(.Moment, subtype: .Any, options: nil)

    resultCollections.enumerateObjectsUsingBlock({
        (object, index, stop) -> Void in


        let collection = object as! PHAssetCollection


        let formatter = NSDateFormatter()
        formatter.dateStyle = NSDateFormatterStyle.MediumStyle
        formatter.timeStyle = .ShortStyle


        var date =  collection.startDate
        var location = collection.approximateLocation?.coordinate


        // ADD PIN
        if location != nil {

            let dateString = formatter.stringFromDate(date!)

            let annotationOne = CustomPointAnnotation()
            annotationOne.coordinate = location!
            annotationOne.title = dateString
            annotationOne.pinCustomImageName = "pin.png"
            annotationOne.belongTo = collection
            annotationOne.image = UIImage(named:annotationOne.pinCustomImageName)

            self.mapView.addAnnotation(annotationOne)

        }
    }) 

0 个答案:

没有答案