【问题标题】:Detect where the image was taken (location) in objective-c在objective-c中检测图像的拍摄位置(位置)
【发布时间】:2012-09-04 06:50:57
【问题描述】:

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

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

干杯

【问题讨论】:

标签: iphone objective-c ios xcode


【解决方案1】:
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 获取它们。

【讨论】:

  • 嗯,这个解决方案需要特定版本的 iOS。如果您出于任何原因需要向下兼容,那么您可能需要查看code.google.com/p/iphone-exif。
猜你喜欢
  • 1970-01-01
  • 2015-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
相关资源
最近更新 更多