Reputation: 678
Is there any method to write GPS info into one image? for example, I want to develop a camera app that can take photos with location information. Can I use PhotoKit related methods or some other methods such as ImageIO? Thanks.
Upvotes: 0
Views: 108
Reputation: 74
Update for Swift 5 / Xcode 14:
PHPhotoLibrary.shared().performChanges ({
let assetLocationChangeRequest = PHAssetChangeRequest(for: lastImageAsset)
assetLocationChangeRequest.location = imageLocation
}) { success, error in
if (success) {
print("Succesfully saved location to image")
} else {
print("Failed to save with Error : \(error!)")
}
}
Upvotes: 0
Reputation: 11127
You can add location information to your image like this
let locationCordinate = CLLocationCoordinate2DMake(lat, long)
let currentDate = NSDate()
let imageLocation = CLLocation(coordinate: locationCordinate, altitude: 0.0, horizontalAccuracy: 0.0, verticalAccuracy: 0.0, timestamp: currentDate)
After this you can add this location to your image like this
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let assetLocationChangeRequest = PHAssetChangeRequest(forAsset: lastImageAsset)
assetLocationChangeRequest.location = imageLocation
}, completionHandler: {
(success:Bool, error:NSError?) -> Void in
if (success) {
print("Succesfully saved location to image")
} else {
print("Failed to save with Error : \(error!)")
}
})
Upvotes: 1