OGeek|极客世界-中国程序员成长平台

标题: ios - 从图像Objective c中提取经纬度 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 13:15
标题: ios - 从图像Objective c中提取经纬度

我在从图像(包含地理位置详细信息)获取纬度和经度数据时遇到问题。我已经导入了 EXIF 框架,我正在使用以下代码来实现这一点:

 NSData *jpegData = [UIImageJPEGRepresentation(image, 0.5) base64String];
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: jpegData];
EXFMetaData* exifData = jpegScanner.exifMetaData;
id latitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLatitude]];
id longitudeValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_GPSLongitude]];
NSLog(@"Longitude: %@  Longitude: %@", latitudeValue, longitudeValue);

但是它返回纬度和经度的 NULL 值,谁能告诉我我在上面的代码中做错了什么?请帮帮我。提前致谢!!



Best Answer-推荐答案


您可以使用 框架。

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
[assetsLibrary assetForURL:photoUrl resultBlock:resultBlock failureBlock:nil];
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *photoAsset) {        
    CLLocation *location = [photoAsset valueForProperty:ALAssetPropertyLocation];

    NSMutableDictionary *exifDataDict = [[NSMutableDictionary alloc] init];
    if (location != nil) {
        [exifDataDict setObject:[NSNumber numberWithDouble:location.coordinate.latitude] forKey"latitude"];
        [exifDataDict setObject:[NSNumber numberWithDouble:location.coordinate.longitude] forKey"longitude"];
    }
}

关于ios - 从图像Objective c中提取经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18018244/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4