1

我正在做一个项目,该项目将要求用户从相机或照片库中拍摄图像,然后获取拍摄图像的位置。我已经使用 UIImagePickerController 来获取图像,我需要知道检测当前位置(如果图像是从相机拍摄的)或拍摄图像的位置(如果图像是从照片库中选择的)

任何人都可以帮助或指导我获得有用的教程吗?

干杯

4

1 回答 1

4
NSData* jpegData =  UIImageJPEGRepresentation(pImage);

    CGImageSourceRef imageData= CGImageSourceCreateWithData((CFDataRef)jpegData, NULL);
    NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(imageData, 0, NULL);

这将提供带有 EXIF 区域的字典。您感兴趣的是 GPS 数据。您使用以下方法提取它们:

NSDictionary *exifGPSDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy]autorelease];
   // you don't have to autorelease when you use ARC

此 exifGPSDictionary 保存您使用键kCGImagePropertyGPSLatitude和查找的值kCGImagePropertyGPSLongitude。然后你使用objectForKey.

于 2012-09-04T09:15:31.010 回答