2014-12-03 6 views
7

Ich würde gerne danken, wenn jemand helfen könnte. Ich lerne diese sehr gut swift Beispielcode aus https://www.youtube.com/watch?v=ztIBNHOm35E oder https://github.com/TDAbboud/PhotosGalleryAppimagePickerController mit GPS-Daten (Swift)

verfolge ich die GPS-Daten von ausgewählten Camera Roll Foto. Welche App muss verwendet werden? imagePickerController Wählen Sie ein beliebiges Foto aus und legen Sie es im App Album ab. Aber die GPS-Daten fehlten in der folgenden Funktion (um ein Foto aus der Kamerarolle auszuwählen und dann in das App-Album aufzunehmen).

Meine Frage: Wie verwendet man imagePickerController, um GPS aufzunehmen, um ein Foto/Bild im neuen Album zu erstellen.

Code Here

//UIImagePickerControllerDelegate Methods 
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){ 

    // http://stackoverflow.com/questions/26391158/getting-metadata-in-swift-by-uiimagepickercontroller?rq=1 
    let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary //Try to get gps info 
    let image = info[UIImagePickerControllerOriginalImage] as? UIImage 
    //Implement if allowing user to edit the selected image 
    //let editedImage = info.objectForKey("UIImagePickerControllerEditedImage") as UIImage 

     let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT 
     dispatch_async(dispatch_get_global_queue(priority, 0), { 
      PHPhotoLibrary.sharedPhotoLibrary().performChanges({ 
       let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(image) 
       let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset 
       let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection, assets: self.photosAsset)! 
      albumChangeRequest.addAssets([assetPlaceholder!]) 
      }, completionHandler: {(success, error)in 
       dispatch_async(dispatch_get_main_queue(), { 
        NSLog("Adding Image to Library -> %@", (success ? "Sucess":"Error!")) 
        picker.dismissViewControllerAnimated(true, completion: nil) 
        }) 
      }) 

     }) 
    } 
    func imagePickerControllerDidCancel(picker: UIImagePickerController!){ 
    picker.dismissViewControllerAnimated(true, completion: nil) 
    } 
} 
+0

http://stackoverflow.com/questions/7965299/write-uiimage-along-with-metadata-exif-gps-tiff-in-iphones-photo-library –

+0

Habe meine Antwort Hilfe? Wenn ja, bitte akzeptiere es. – fuzz

Antwort

2

Try this:

Denken Sie daran, import AssetsLibrary

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { 
    picker.dismissViewControllerAnimated(true, completion: {() in 
     if (picker.sourceType == .PhotoLibrary) { 
      let image = info[UIImagePickerControllerOriginalImage] as! UIImage 
      let library = ALAssetsLibrary() 
      var url: NSURL = info[UIImagePickerControllerReferenceURL] as! NSURL 

      library.assetForURL(url, resultBlock: { (asset: ALAsset!) in 
        if asset.valueForProperty(ALAssetPropertyLocation) != nil { 
         let latitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.latitude 
         let longitude = (asset.valueForProperty(ALAssetPropertyLocation) as! CLLocation!).coordinate.longitude 
         println("\(latitude), \(longitude)") 
        } 
       }, 
       failureBlock: { (error: NSError!) in 
        println(error.localizedDescription) 
       }) 
     } 
    }) 
} 
0

Änderung

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: NSDictionary!){ 

zu

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){ 
Verwandte Themen