CLLocation Tag Image GeoLocation in IPhone Swift 4
If u want to save data image with geolocation follow this step below, it's just can read in mac os and Iphone not for write exif metadata file .
import UIKit
import CoreLocation
import Photos
import ImageIO
import MobileCoreServices
class SaveDataImageVC: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var imageView: UIImageView!
var locManager = CLLocationManager()
var currentLocation: CLLocation!
override func viewDidLoad() {
super.viewDidLoad()
locManager.delegate = self
locManager.desiredAccuracy = kCLLocationAccuracyBest
locManager.requestAlwaysAuthorization()
locManager.startUpdatingLocation()
let cllocation = locManager.location?.coordinate
addAsset(image: imageCoordinate.image!, location: locManager.location)
}
func addAsset(image: UIImage, location: CLLocation? = nil) {
PHPhotoLibrary.shared().performChanges({
// Request creating an asset from the image.
let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: image)
// Set metadata location
if let location = location {
creationRequest.location = location
}
}, completionHandler: { success, error in
if !success { NSLog("error creating asset: \(String(describing: error))") }
})
}
}
No comments: