(PHAsset location) returns (null) 对于相机胶卷照片,即使启用了定位服务
(PHAsset location) returns (null) for Camera Roll photo even though location services are enabled
我需要访问来自用户相机 roll/photo 库的用户提交照片的 GPS 坐标。为了现代性,我正在实施 PHAsset 而不是 ALAsset 。
我知道位置服务已启用,因为我可以打印出用户的当前位置并将 "NSLocationAlwaysUsageDescription"、"NSLocationWhenInUseDescription" 和 "privacy - location usage description" 键添加到我的 info.plist 文件。我已经在 ViewController.
的 .h 文件中导入了 CoreLocation、MobileCoreServices 和 Photos
我当前在didFinishPickingMediaWithInfo委托方法中的代码如下:
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *res = [PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:url] options:nil];
PHAsset *thisPhoto = [res objectAtIndex: 0];
CLLocation *photoLocation = [thisPhoto location];
NSLog(@"%@", photoLocation);
出于某种原因,这总是输出 (null)。是否有什么东西让我无法访问 PHAsset 位置数据?我知道 PHAsset 已正确分配,因为 [PHAsset creationDate] 适用于我选择的任何照片。
谢谢!
您确实有权访问 PHAsset 位置数据(前提是它可用)。用户可以选择不允许相机应用程序访问位置服务,这会导致照片没有位置数据。
我需要访问来自用户相机 roll/photo 库的用户提交照片的 GPS 坐标。为了现代性,我正在实施 PHAsset 而不是 ALAsset 。
我知道位置服务已启用,因为我可以打印出用户的当前位置并将 "NSLocationAlwaysUsageDescription"、"NSLocationWhenInUseDescription" 和 "privacy - location usage description" 键添加到我的 info.plist 文件。我已经在 ViewController.
的 .h 文件中导入了 CoreLocation、MobileCoreServices 和 Photos我当前在didFinishPickingMediaWithInfo委托方法中的代码如下:
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *res = [PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:url] options:nil];
PHAsset *thisPhoto = [res objectAtIndex: 0];
CLLocation *photoLocation = [thisPhoto location];
NSLog(@"%@", photoLocation);
出于某种原因,这总是输出 (null)。是否有什么东西让我无法访问 PHAsset 位置数据?我知道 PHAsset 已正确分配,因为 [PHAsset creationDate] 适用于我选择的任何照片。
谢谢!
您确实有权访问 PHAsset 位置数据(前提是它可用)。用户可以选择不允许相机应用程序访问位置服务,这会导致照片没有位置数据。