【发布时间】:2015-06-12 05:46:44
【问题描述】:
我想从相机拍摄的照片中获取纬度、经度或地址,我使用了链接iPhone Get UIImagePickerController Lat/Lng
我使用的代码是,
这就是我们处理选择器提供的信息的方式:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([picker sourceType] == UIImagePickerControllerSourceTypePhotoCamera) {
// We'll store the info to use in another function later
self.imageInfo = info;
// Get the asset url
NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
// We need to use blocks. This block will handle the ALAsset that's returned:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
// Get the location property from the asset
CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
// I found that the easiest way is to send the location to another method
[self handleImageLocation:location];
};
// This block will handle errors:
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can not get asset - %@",[myerror localizedDescription]);
// Do something to handle the error
};
// Use the url to get the asset from ALAssetsLibrary,
// the blocks that we just created will handle results
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock:resultblock
failureBlock:failureblock];
}
}
但是位置变量返回 nil。如何从相机拍摄的照片中提取位置或地址。
【问题讨论】:
-
@Ani Prasad。实际上我只关注了那个链接。如果你观察到有相同的代码
-
照片本地化了吗?如果你去 Photos.app 并选择它,它是本地化的吗?例如,从(FaceBook、WhatsApp 等)获取的屏幕截图或照片可能未本地化。
标签: ios objective-c