我正试图通过PHAssets
获取图像和视频的地理位置,正在获取图像位置。
PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: opts).
当我使用下面相同的视频代码时,返回零。
PHAsset.fetchAssetsWithALAssetURLs([videoUrl], options: opts)
答案 0 :(得分:0)
这是在iOS 8上进行测试,适用于视频,因此对于带有一些调整的照片,它应该会有类似的效果。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *videoUrl = (NSURL *)[info objectForKey:UIImagePickerControllerMediaURL];
NSString *moviePath = [videoUrl path];
if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath) ) {
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];
NSLog(@"Location Meta: %@", location);
} failureBlock:^(NSError *error) {
NSLog(@"Video Date Error: %@", error);
}];
}
}
答案 1 :(得分:0)
获取所有视频Gelocation
PHPhotoLibrary.requestAuthorization { (status) -> Void in
let videosOption = PHFetchOptions()
videosOption.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue)
videosOption.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let allVids = PHAsset.fetchAssets(with: videosOption)
for index in 0..<allVids.count {
//print Location here
print(allVids[index].location as Any)
}
}