我是IOS的新手,所以我不知道我错过了什么,但我已经通过this网站从图片中获取位置详细信息,但没有运气。 如果有人能提供帮助,那就太棒了。 以下代码位于 UIImagepicker的 didFinishPickingMediaWithInfo 函数内
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,
nil];
NSLog(@"Image properties %@",imageProperties);
NSData *data=UIImageJPEGRepresentation(img, 0);
CGImageSourceRef source=CGImageSourceCreateWithData((CFDataRef)data, NULL);
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, (CFDictionaryRef)options);
CFDictionaryRef gps = CFDictionaryGetValue(imageProperties, kCGImagePropertyGPSDictionary);
NSLog(@"GPS %@",gps);
if (gps) {
NSString *latitudeString = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLatitude);
NSString *latitudeRef = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLatitudeRef);
NSString *longitudeString = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLongitude);
NSString *longitudeRef = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLongitudeRef);
NSLog(@"GPS Coordinates: %@ %@ / %@ %@", longitudeString, longitudeRef, latitudeString, latitudeRef);
}
输出:
Image properties
{
ColorModel = RGB;
Depth = 8;
Orientation = 6;
PixelHeight = 720;
PixelWidth = 960;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 960;
PixelYDimension = 720;
};
"{JFIF}" = {
DensityUnit = 0;
JFIFVersion = (
1,
0,
1
);
XDensity = 72;
YDensity = 72;
};
"{TIFF}" = {
Orientation = 6;
};
}
GPS (null)
因此Image确实附加了位置,但在获取时,它显示地理位置为null。
谢谢。