Dim NaObj As NativeObject = Me
'Save to PhotoAlbum
NaObj.RunMethod("SetGPS:Type:GPSLatitude:GPSLongitude:GPSLatitudeRef:GPSLongitudeRef:DataPath:WriteInPhotoAlbum:",Array(LoadBitmap(File.DirAssets,"x.jpg"),"JPEG",1.1,2.2,"lat_ref","lon_ref",Null,True))
'Save to Directory
NaObj.RunMethod("SetGPS:Type:GPSLatitude:GPSLongitude:GPSLatitudeRef:GPSLongitudeRef:DataPath:WriteInPhotoAlbum:",Array(LoadBitmap(File.DirAssets,"x.jpg"),"JPEG",1.1,2.2,"lat_ref","lon_ref",File.Combine(File.DirDocuments,"x.jpeg"),False))
End Sub
#If OBJC
#import <ImageIO/ImageIO.h>
#import <AssetsLibrary/AssetsLibrary.h>
- (void)SetGPS:(UIImage *)Image Type:(NSString*)Type GPSLatitude:(float)GPSLatitude GPSLongitude:(float)GPSLongitude GPSLatitudeRef:(NSString*)GPSLatitudeRef GPSLongitudeRef:(NSString*)GPSLongitudeRef DataPath:(NSString*)DataPath WriteInPhotoAlbum:(BOOL)WriteInPhotoAlbum {
  NSData* ImageData;
 
  if ([Type isEqualToString:@"JPEG"]){
     ImageData =  UIImageJPEGRepresentation(Image, 1.0);
  }else if ([Type isEqualToString:@"PNG"]){
     ImageData =  UIImagePNGRepresentation(Image);
  }
   CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)ImageData, NULL);
   
  NSDictionary *metadata = (__bridge NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
  NSMutableDictionary *metadataAsMutable = [metadata mutableCopy];
   
  NSMutableDictionary *GPSDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy];
  if(!GPSDictionary)
  {
     NSDictionary * dictionary = nil;
  GPSDictionary = [NSMutableDictionary dictionary];
  }
  [GPSDictionary setValue:[NSNumber numberWithFloat:GPSLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
  [GPSDictionary setValue:[NSNumber numberWithFloat:GPSLongitude] forKey:(NSString*)kCGImagePropertyGPSLongitude];
  [GPSDictionary setValue:GPSLatitudeRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
  [GPSDictionary setValue:GPSLongitudeRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
  [metadataAsMutable setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
   
   if (WriteInPhotoAlbum == YES){
   
     ALAssetsLibrary *library = [ALAssetsLibrary alloc];
     ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock =
     ^(NSURL *newURL, NSError *error) {
  if (error) {
  NSLog( @"Error writing image with metadata to Photo Library: %@", error );
  } else {
  NSLog( @"Wrote image %@ with metadata %@ to Photo Library",newURL,metadataAsMutable);
  }
     };
     [library writeImageToSavedPhotosAlbum:Image.CGImage
  metadata:metadataAsMutable
  completionBlock:imageWriteCompletionBlock];
   
   }else{
   
     CFStringRef UTI = CGImageSourceGetType(source);
     NSMutableData *dest_data = [NSMutableData data];
     CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef) dest_data, UTI, 1, NULL);
     if(!destination){
      NSLog(@"--------- Could not create image destination---------");
     }
     CGImageDestinationAddImageFromSource(destination, source, 0, (CFDictionaryRef) metadataAsMutable);
     BOOL success = NO;
     success = CGImageDestinationFinalize(destination);
     
     if(!success){
      NSLog(@"-------- could not create data from image destination----------");
     }else{
       [dest_data writeToFile:DataPath atomically:YES];
       NSLog( @"Wrote image to %@ with metadata %@",DataPath,metadataAsMutable);
     }
   }
   
}
#End If