Hi Omar,
I also was trying to insert GPS data in the XMP files, and came on to the same problem you encountered. I also don't understand why specific EXIF fields cannot be updated. I know they shouldn't be updated (in an user interface), but sometimes there are some exception, like we can find in this thread here.
However, I finally did find a solution, but it need some more testing to say it really works under all circumstances. Perhaps it can also be of any help on ohter EXIF fields.
Here is my solution:
1) Create a new XMPMeta object and fill in your GPS fields
2) Get the current XMP metadata from the selected thumbnail
3) Use XMPUtils.appendProperties to combine the two meta data objects
4) Write the appended metadata to the XMP file
5) Write the appended metadata back to the current thumbnail
I've used the following script snippit:
var xmp = new XMPMeta();
xmp.setProperty(XMPConst.NS_EXIF,'GPSLongitude',longitude);
xmp.setProperty(XMPConst.NS_EXIF,'GPSLatitude',latitude);
xmp.setProperty(XMPConst.NS_EXIF,'GPSAltitude',altitude);
xmp.setProperty(XMPConst.NS_EXIF,'GPSMapDatum','WGS-84');
var md = thumb.synchronousMetadata;
var xmp2 = new XMPMeta(md.serialize());
XMPUtils.appendProperties(xmp,xmp2,XMPConst.APPEND_ALL_PROPERTIES | XMPConst.APPEND_REPLACE_OLD_VALUES | XMPConst.APPEND_DELETE_EMPTY_VALUES);
var xmpFile2 = new XMPFile(thumb.spec.fsName,XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (xmpFile2.canPutXMP(xmp2))
xmpFile2.putXMP(xmp2);
xmpFile2.closeFile();
var xml = xmp2.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
thumb.metadata = new Metadata(xml);
I have not tested this with JPG and TIFF files. I have tested a bit with existing and non existing XMP files.
Any suggestions are very welcome!
Erwin