ALAsset долготу и широту из метаданных

Приложение для 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?? Спасибо


person user3102075    schedule 08.03.2014    source источник
comment
вы должны дать отзыв об ответе, который работает или нет.   -  person Nitin Gohel    schedule 08.03.2014


Ответы (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:^{

            }];

}
person Nitin Gohel    schedule 08.03.2014