tdon
tdon

Reputation: 1441

Query IOS photo library based on location in Swift

I'm new to the Photos framework and predicates, so bear with me. I found that you can query the photo library based on the creation date of the photo by using something like this:

let fetchOptions = PHFetchOptions() fetchOptions.predicate = NSPredicate(format: "creationDate > %@ AND creationDate < %@", startDate, endDate)

Is there a way to query based on a range of latitudes and longitudes? For example: get all the pictures in the photo library between (48.512511, -121.047363) and (48.479458, -120.976295)?

Upvotes: 1

Views: 998

Answers (1)

Kumuluzz
Kumuluzz

Reputation: 2012

Unfortunately the PHFetchOptions does not support querying for location. The supported keys can be seen in the documentation:

https://developer.apple.com/library/ios/documentation/Photos/Reference/PHFetchOptions_Class/index.html

The only possible solution for you is to fetch all photos and then filter the PHAssets in memory based on the location property:

https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAsset_Class/index.html#//apple_ref/occ/instp/PHAsset/location

Upvotes: 1

Related Questions