Saving Geotag info with photo on iOS4.1

后端 未结 6 1346
旧时难觅i
旧时难觅i 2020-12-01 03:21

I am having major issues trying to save a photo to camera roll with geotag info on iOS4.1. I am using following ALAssetsLibrary API:

- (void)writeImageDataTo         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-01 03:42

    After much searching I found and adapted this

    This turns cclocation data into a suitable NSDictionary

     #import 
    
    +(NSMutableDictionary *)updateExif:(CLLocation *)currentLocation{
    
    
        NSMutableDictionary* locDict = [[NSMutableDictionary alloc] init];
    
    
        CLLocationDegrees exifLatitude = currentLocation.coordinate.latitude;
        CLLocationDegrees exifLongitude = currentLocation.coordinate.longitude;
    
        [locDict setObject:currentLocation.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp];
    
        if (exifLatitude <0.0){
            exifLatitude = exifLatitude*(-1);
            [locDict setObject:@"S" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
        }else{
            [locDict setObject:@"N" forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
        }
        [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
    
        if (exifLongitude <0.0){
            exifLongitude=exifLongitude*(-1);
            [locDict setObject:@"W" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
        }else{
            [locDict setObject:@"E" forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
        }
        [locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString*) kCGImagePropertyGPSLongitude];
    
    
        return [locDict autorelease];
    
    }
    

    Then I add it to the existing metadata that you get through the camera (which doesn't by default have the gps data)

    I get the original metadata like this

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{  
        [imageMetaData setDictionary:[[info objectForKey:UIImagePickerControllerMediaMetadata] copy]];
    }
    

    then I add the gps dictionary the previous method produces.

    [imageMetaData setObject:currentLocation forKey:(NSString*)kCGImagePropertyGPSDictionary];          
    
        [library writeImageToSavedPhotosAlbum:[viewImage CGImage] metadata:imageMetaData completionBlock:photoCompblock];   
    

提交回复
热议问题