我想从照片库中获取地理位置(纬度/经度+距离)周围的所有图像。 目前,我正在使用以下代码。它可以工作,但这意味着我需要遍历所有PHAsset,是否有更好的解决方案?我发现没有有用的谓词可用于PHFetchOptions。
let photosFetchResult = PHAsset.fetchAssets(with: nil)
let poiLocation = CLLocation(latitude: geoLocation.coordinate.latitude, longitude: geoLocation.coordinate.longitude)
// find all images located near the geolocation
var filteredImages = [LocalImage]()
for i in 0..<photosFetchResult.count {
let currentObject = photosFetchResult.object(at: i)
if let imageLocation = currentObject.location {
let distanceFromPoi = poiLocation.distance(from: imageLocation)
if distanceFromPoi <= Cste.radiusSearchImage {
filteredImages.append(LocalImage(image: getAssetThumbnail(asset:currentObject),
asset: currentObject,
distanceFrom: distanceFromPoi))
}
}
谢谢