Search code examples
iosgeolocationuiimageuiimagepickercontrollerphoto-upload

Upload Photo to server including location information (Lat/Long)


Why is it so hard to upload a photo with Location data in its exif to the server? I am breaking my head not being able to solve this. Whenever I am sending the photo to the server all of its location information is being stripped off from the photo.

I have tried getting UIImage from the UIImagePickerController using both

NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];

and also UIImagePickerControllerOriginalImage.

Kindly someone help me


Solution

  • To preserve the exif info, you need to use the raw data, not just the UIImage. You can get it from the ALAsset's defaultRepresentation, something like this:

    ALAssetRepresentation* representation = [myAsset defaultRepresentation];
    int size = representation.size;
    NSMutableData* data = [[NSMutableData alloc]initWithCapacity:size];
    void* buffer = [data mutableBytes];
    [representation getBytes:buffer fromOffset:0 length:size error:nil];
    data = [NSMutableData dataWithBytes:buffer length:size];
    

    I'm not near xcode to test it right now, but it should work.