我正在尝试获取图像和视频的地理位置,虽然图像位置是通过获取的。

PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: opts).

当我在视频中使用下面相同的代码时,返回0。
PHAsset.fetchAssetsWithALAssetURLs([videoUrl], options: opts)

最佳答案

这是在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);
        }];

    }

}

10-08 05:56
查看更多