Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHAsset Location -- GPS MetaData, what's wrong?

trying to add location from a UIImage using Phasset:

// image is a variable like so: image: UIImage

var newAsset = PHAssetChangeRequest.creationRequestForAssetFromImage(image)
newAsset.location = CLLocation(latitude: coordinate.latitude, coordinate.longitude)

this code works, apparently -> save a new asset into the photo library with the good coordinate. I can see it in the library itself.

but when I use exif tools and similar, most of the time, GPS dictionnary is empty as if location was not set. (also, I noticed GPS info is not in exif format) so I guess, location information is also somewhere else...

so what's wrong with location property of PHAsset ? how can set properly location ?

like image 351
raphael Avatar asked Mar 15 '23 06:03

raphael


1 Answers

Photos tracks location metadata it its own database, separately from the EXIF metadata stored in each photo file. When you (as a client of the Photos API) or the user creates/adds a new asset, Photos reads the EXIF location data from the file and sets the location in its database to match. Beyond that, however, the Photos API makes no effort to keep these in sync.

If you want to update the EXIF metadata in the file, you'll need to do that yourself. (Image I/O can help with that — see this answer.) Then, add the whole file, not just a UIImage created from it, to Photos using creationRequestForAssetFromImageAtFileURL: or the new PHAssetCreationRequest stuff in iOS 9.

like image 132
rickster Avatar answered Mar 28 '23 00:03

rickster