可能重复:
How Do I Get The Correct Latitude and Longitude From An Uploaded iPhone Photo?
我需要从使用iPhone相机拍摄并从相机胶卷中选择的照片访问地理编码位置(纬度和经度)信息。首先,用相机拍摄的照片......
使用相机拍摄图像后,我正在使用以下代码。然后我将图像元数据拉出并存储到NSMutableDictionary中。但是我没有在字典中看到任何GPS信息......它在哪里?我如何访问此信息。我找不到关于这方面的好文件......
以下代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// snip out code above to keep this question short.
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
{
// images taken with camera have direct access to the metadata by using UIImagePickerControllerMediaMetadata
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
NSLog(@"dictionary: %@", metadata);
// rest of code snipped out to keep this question short
NSLog输出以下信息 - 但没有GPS信息
dictionary: {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.970853654340484";
BrightnessValue = "-1.198278557694757";
ColorSpace = 1;
DateTimeDigitized = "2012:04:11 21:55:29";
DateTimeOriginal = "2012:04:11 21:55:29";
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.06666666666666667";
FNumber = "2.8";
Flash = 24;
FocalLength = "3.85";
ISOSpeedRatings = (
1000
);
MeteringMode = 5;
PixelXDimension = 2592;
PixelYDimension = 1936;
SceneType = 1;
SensingMethod = 2;
Sharpness = 1;
ShutterSpeedValue = "3.911199862602335";
SubjectArea = (
1295,
967,
699,
696
);
WhiteBalance = 0;
};
"{TIFF}" = {
DateTime = "2012:04:11 21:55:29";
Make = Apple;
Model = "iPhone 4";
Software = "5.0.1";
XResolution = 72;
YResolution = 72;
};
我也尝试过另一种方法,使用ALAssetLibrary但是我从不输入我的if
语句,只输入else
部分 - 这显然会产生与上面相同的信息。结果是,没用,因为我还没有任何GPS数据。
代码如下:
创建名为@property
NSMutableDictionary
类型photoMetadataDictionary_
然后在.m文件中执行以下操作:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.1f)
{
NSURL* assetURL = nil;
if ((assetURL = [info objectForKey:UIImagePickerControllerReferenceURL]))
{
// I never get here... Not sure why...
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL resultBlock:^(ALAsset *asset)
{
NSDictionary *metadata = asset.defaultRepresentation.metadata;
[photoMetadataDictionary_ addEntriesFromDictionary:metadata];
}
failureBlock:^(NSError *error)
{
}];
}
else
{
NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
if (metadata)
{
[photoMetadataDictionary_ addEntriesFromDictionary:metadata];
}
}
}