Geo-tagging Images

 Roi y Zysman made an entry on his blog about geotagging jpgs images with a few lines of code in C#.   Very useful.  Takn directly from his site:


 appears that it is very simple to read and write these GPS settings from within the JPEG image using .Net’s System.Drawing.Image class.
The data stored in JPEG images complies with the EXIF data format. We can use the Image class to read and write data from and to the JPEG image.
here is an example:
Image Pic = Image.FromFile(Filename);  PropertyItems = Pic.PropertyItems;  PropertyItems[0].Id = 0x0002; //index of the EXIF TAG  PropertyItems[0].Type = 5;//  PropertyItems[0].Len = length;  PropertyItems[0].Value =new byte[length];  Pic.SetPropertyItem(PropertyItems[0]);

And that’s pretty much it, there are a few more tweaks to save the image.
I’m publishing here a small C# file with a static function to perform a simple action to embed GPS latitude, longitude (Which can be taken from the gps log according to time that the picture was taken).
It is pretty much straight forward.
It can be used like so

WriteLongLat(“c:/temp/house_gps.jpg”, 33, 0, 48.46, 35, 5, 38.12);

where the first parameter represents the file name to be embedded and the other parameters represent the lon and lat degrees, minutes, and seconds..
Feel free to use this as will (LGPL) license