geolocation - How to write GPS coordinates to EXIF data on Android -


i'm trying write geotagging app user selects image form photo gallery, , image gets current gps coordinates written through exif file.

so far able pull gallery, select image, , find current gps coordinates, cannot write coordinates exif file. whenever select image, can view it, no data written exif file.

i have looked several examples how write exif, , code looks correct (to me @ least). can me figure out why not writing data?

here's code:

//place gps cords exif file         try {             exifinterface exif = new exifinterface("/sdcard/dcim/100media/imag0020.jpg");              exif.setattribute(exifinterface.tag_gps_latitude, dmsconv(lat));             exif.setattribute(exifinterface.tag_gps_longitude,dmsconv(lon));             if (lat > 0)                exif.setattribute(exifinterface.tag_gps_latitude_ref, "n");              else                             exif.setattribute(exifinterface.tag_gps_latitude_ref, "s");             if (lon > 0)                exif.setattribute(exifinterface.tag_gps_longitude_ref, "e");                  else                             exif.setattribute(exifinterface.tag_gps_longitude_ref, "w");             exif.saveattributes();          } catch (ioexception e) {             e.printstacktrace();         }   //convert decimal degrees dms string dmsconv(double coord) {         coord = (coord > 0) ? coord : (-1)*coord;  // -105.9876543 -> 105.9876543       string sout = integer.tostring((int)coord) + "/1,";   // 105/1,       coord = (coord % 1) * 60;         // .987654321 * 60 = 59.259258       sout = sout + integer.tostring((int)coord) + "/1,";   // 105/1,59/1,       coord = (coord % 1) * 6000;             // .259258 * 6000 = 1555       sout = sout + integer.tostring((int)coord) + "/1000";   // 105/1,59/1,15555/1000       return sout;     } 

thanks help!

edit: @ time trying hardcode file path , name exifinterface, that's why says "/sdcard/dcim/100media/imag0020.jpg"instead of filename. have problem?

solved it. hardcoding file path problem. used code

        int columnindex = cursor.getcolumnindex(filepathcolumn[0]);         string picturepath = cursor.getstring(columnindex); 

to obtain picturepath used in

exifinterface exif = new exifinterface(picturepath); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -