the above code works, but I had to modify the set_gps_location function to work with the current version of pyexiv2...perhaps Maksym was using an older version:
def set_gps_location(file_name, lat, lng):
"""Adds GPS position as EXIF metadata
Keyword arguments:
file_name -- image file
lat -- latitude (as float)
lng -- longitude (as float)
"""
lat_deg = to_deg(lat, ["S", "N"])
lng_deg = to_deg(lng, ["W", "E"])
print lat_deg
print lng_deg
# convert decimal coordinates into degrees, munutes and seconds
exiv_lat = (pyexiv2.Rational(lat_deg[0]*60+lat_deg[1],60),pyexiv2.Rational(lat_deg[2]*100,6000), pyexiv2.Rational(0, 1))
exiv_lng = (pyexiv2.Rational(lng_deg[0]*60+lng_deg[1],60),pyexiv2.Rational(lng_deg[2]*100,6000), pyexiv2.Rational(0, 1))
metadata = pyexiv2.ImageMetadata(file_name)
metadata.read()
## exif_keys = metadata.exif_keys
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lng
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lng_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata.write()