Get GPS location from MLMediaObject on OS X

2019-06-09 04:39发布

问题:

I'm getting started with the Media Library Framework on OS X, specifically with regard to accessing a user's Photos library. After a lot of wrangling I was able to get access to each photo as a MLMediaObject, but now I've hit a roadblock:

How can I access the GPS location of the photo, from the MLMediaObject?

This sort of information is easy to get from the old ALAssetsLibrary system, or from the Photos Framework on iOS, using a CLLocation property associated with the media object, but I can't seem to figure it out with the Media Library Framework. The documentation lists these as the only properties of the MLMediaObject:

attributes
mediaType
contentType
name
URL
originalURL
fileSize
modificationDate
thumbnailURL
artworkImage

At first I thought attributes looked promising, but as far as I can tell there are a very small number of options for that property, and none of them are related to the location.

Then I thought, if I have the file's URL, I ought to be able to get the GPS info directly from the file, but that is proving much more difficult than I expected.

Is there an established means of getting the CLLocation, or other form of GPS data, from a photo using the MLMediaObject? Or if not, can anyone think of a more roundabout way of getting access to that information, starting from an MLMediaObject?

回答1:

In my case I have keys latitude and longitude in attributes. So I assume that it's GPS location of the photo.