How to save GPS coordinates in exif data on Android?

前端 未结 5 1424
借酒劲吻你
借酒劲吻你 2020-12-02 20:43

I am writing GPS coordinates to my JPEG image, and the coordinates are correct (as demonstrated by my logcat output) but it appears that it\'s being corrupted somehow. Readi

5条回答
  •  生来不讨喜
    2020-12-02 21:32

    ExifInterface exif = new ExifInterface(compressedImage.getPath());
            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,gpsTracker.dec2DMS(gpsTracker.getLatitude()));
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,gpsTracker.dec2DMS(gpsTracker.getLongitude()));
    

    Convertor double to String

     String dec2DMS(double coord) {
        coord = coord > 0 ? coord : -coord;  
        String sOut = Integer.toString((int)coord) + "/1,";   
        coord = (coord % 1) * 60;         
        sOut = sOut + Integer.toString((int)coord) + "/1,";   
        coord = (coord % 1) * 60000;             
        sOut = sOut + Integer.toString((int)coord) + "/1000";   
        return sOut;
    }
    

提交回复
热议问题