AL从元数据中设置经度和纬度

 渊博的蓝天大海_210 发布于 2023-01-19 12:14

Iphone应用程序,我需要从图像中提取经度和纬度,到目前为止所有工作,除了获取gps数据.我在imagePickerController中有这个代码:

- (UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibrary *library1 = [[ALAssetsLibrary alloc] init];
    [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
        ALAssetRepresentation *rep = [asset defaultRepresentation];
        NSDictionary *metadata = rep.metadata;
        NSLog(@"%@", metadata);

        CGImageRef iref = [rep fullScreenImage] ;

        if (iref) {
            self.myPicture.image = [UIImage imageWithCGImage:iref];
        }
    } failureBlock:^(NSError *error) {
        // error handling
    }];
}

这输出:

...
     Sharpness = 2;
    ShutterSpeedValue = "9.710661431591664";
    SubjectArea =         (
        1295,
        967,
        699,
        696
    );
    WhiteBalance = 0;
};
"{GPS}" =     {
    Altitude = "144.8338028169014";
    AltitudeRef = 0;
    DateStamp = "2013:09:07";
    ImgDirection = "243.4423676012461";
    ImgDirectionRef = T;
    Latitude = "37.97166666666666";
    LatitudeRef = N;
    Longitude = "23.72733333333333";
    LongitudeRef = E;
    TimeStamp = "08:10:30";
};
.....

我怎样才能获得经度和纬度并放入NSString?谢谢

1 个回答
  • 使用CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];可以帮助您从拍摄的照片中获取纬度和长度检查以下代码并使用您的要求.

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
        NSLog(@"url %@",info);
    
    
        if ([picker sourceType] == UIImagePickerControllerSourceTypePhotoLibrary) {
    
            // Get the asset url
            NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
            NSLog(@"url %@",url);
            // We need to use blocks. This block will handle the ALAsset that's returned:
            ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
            {
                // Get the location property from the asset
    
    
                CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
                // I found that the easiest way is to send the location to another method
    
                self.lat =location.coordinate.latitude; //[[gpsdata valueForKey:@"Latitude"]floatValue];
                self.lng =location.coordinate.longitude;
                NSLog(@"\nLatitude: %f\nLongitude: %f",self.lat,self.lng);
    
                strLocation=[NSString stringWithFormat:@"La:%f Lo%f",self.lat,self.lng];
    
                NSLog(@"Can not get asset - %@",strLocation);
    
    
            };
            // This block will handle errors:
            ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
            {
                NSLog(@"Can not get asset - %@",[myerror localizedDescription]);
                // Do something to handle the error
            };
    
    
    
            ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
            [assetslibrary assetForURL:url
                           resultBlock:resultblock
                          failureBlock:failureblock];
    
    
    
        }
    
    
        [self dismissViewControllerAnimated:YES completion:^{
    
                }];
    
    }
    

    2023-01-19 12:16 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有