安卓写EXIF GPS经纬度到JPEG失败经纬度、EXIF、安卓写、JPEG

2023-09-12 23:53:29 作者:哇噻你好@

我想补充GPS数据,如经度和纬度成JPEG照片。 照片被按tab键卡捕获(NFC) 在logcat的正确值可被显示,但这些值不能被写入到JPG照片文件!

下面是我的code: 它是用来取保存的JPG文件并调用该方法下面 该方法用于添加的EXIF GPS参数到JPG格式 GPS的参数,如经度和纬度已经采取了另一种活性

我用EXIF浏览器Firefox中看到的结果。

做为IO异常事项的位置?

以下是重要的日志猫日志可致使故障: 11月七号至26日:48:30.386:D / NativeNfcTag(195):标签丢失,重新启动轮询循环

 公共静态无效WRITEFILE(档案照片,双纬度,双经度)抛出IOException异常{


    ExifInterface EXIF​​ = NULL;

    尝试{
        Log.v(latiDouble,+纬度);
        Log.v(longiDouble,+经度);
        EXIF =新ExifInterface(photo.getCanonicalPath());
        如果(EXIF!= NULL){
        双latitu =纬度;
        双longitu =经度;
        双阿拉特= Math.abs(latitu);
        沿着翻倍= Math.abs(longitu);
        字符串stringLati = convertDoubleIntoDegree(ALAT);
        串stringLongi = convertDoubleIntoDegree(沿);
        exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,stringLati);
        exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,stringLongi);
        Log.v(latiString,+ stringLati);
        Log.v(longiString,+ stringLongi);
        exif.saveAttributes();
        字符串拉提= exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
         字符串隆基= exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
         Log.v(latiResult,+ LATI);
         Log.v(longiResult,+茇);

        }
    }赶上(IOException异常E){
        // TODO自动生成的catch块
        e.printStackTrace();

    }

}
 

下面是调用该方法的位置 ......

 光标locationCursor = dbHandler.fetchGpsLocationTypeByAttendInfoID(attendInfoId);
      如果(locationCursor.getCount()大于0){
        双纬度= dbHandler.fetchDoubleItem(locationCursor,纵横);
        双经度= dbHandler.fetchDoubleItem(locationCursor,经度);


            Log.v(纬度,+纬度);
            Log.v(纬度,+经度);

            尝试 {
                GpsUtils.writeFile(photoFile,纬度,经度);
            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }

    }
    dbHandler.close();

    cameraHandler.start preVIEW();
 

解决方案

好吧,我有这个挣扎了很长时间,但终于得到它。我最后一次使用它这个code的工作:

  ExifInterface EXIF​​ =新ExifInterface(imgFile.getCanonicalPath());
              //字符串latitudeStr =90 / 1,12 / 1,30 / 1;
              双纬度= location.getLatitude();
              双阿拉特= Math.abs(LAT);
              字符串DMS = Location.convert(ALAT,Location.FORMAT_SECONDS);
              的String []分割= dms.split(:);
              。的String [] SECNDS =(分割[2])分裂(\\);
              字符串秒;
              如果(secnds.length == 0)
              {
                  秒=拆分[2];
              }
              其他
              {
                  秒= SECNDS [0];
              }

              串latitudeStr =分裂[0] +/ 1,+分裂​​[1] +/ 1,+秒+/ 1;
              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,latitudeStr);

              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,纬度大于0的N:S);

              双LON = location.getLongitude();
              双ALON = Math.abs(LON);


              DMS = Location.convert(ALON,Location.FORMAT_SECONDS);
              拆分= dms.split(:);
              SECNDS =(分割[2])分裂(\\)。

              如果(secnds.length == 0)
              {
                  秒=拆分[2];
              }
              其他
              {
                  秒= SECNDS [0];
              }
              串longitudeStr =分裂[0] +/ 1,+分裂​​[1] +/ 1,+秒+/ 1;


              exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,longitudeStr);
              exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,LON大于0E:W);

              exif.saveAttributes();

          }
 
单片机gps 模块获得经纬度的数据是怎样的

I would like to add GPS data such as longitude and latitude into the jpeg photo. The photo is captured by tabbing the card (NFC) In the logcat correct values can be displayed but these values cannot be written into the jpg photo file !

Below is my code: It is used to take saved jpg files and call the method below The method is used to add EXIF GPS parameters into the jpg The GPS parameters such as longitude and latitude are already taken in another activity.

I use EXIF Viewer in Firefox to see the result.

Does the position for the IO Exception matters?

The following is the important log cat log which may render the failure: 07-26 11:48:30.386: D/NativeNfcTag(195): Tag lost, restarting polling loop

 public static void writeFile (File photo, double latitude, double longitude) throws IOException{


    ExifInterface exif = null;

    try{
        Log.v("latiDouble", ""+latitude);
        Log.v("longiDouble", ""+longitude);
        exif = new ExifInterface(photo.getCanonicalPath());
        if (exif != null) {
        double latitu = latitude;
        double longitu = longitude;
        double alat = Math.abs(latitu);
        double along = Math.abs(longitu);
        String stringLati = convertDoubleIntoDegree(alat);
        String stringLongi = convertDoubleIntoDegree(along);
        exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, stringLati);            
        exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, stringLongi);
        Log.v("latiString", ""+ stringLati);
        Log.v("longiString", ""+ stringLongi);
        exif.saveAttributes();
        String lati = exif.getAttribute (ExifInterface.TAG_GPS_LATITUDE);  
         String longi = exif.getAttribute (ExifInterface.TAG_GPS_LONGITUDE);  
         Log.v("latiResult", ""+ lati);
         Log.v("longiResult", ""+ longi);

        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }

}

The below is the position to call the method ...

    Cursor locationCursor = dbHandler.fetchGpsLocationTypeByAttendInfoID(attendInfoId);
      if (locationCursor.getCount()>0) {
        double latitude = dbHandler.fetchDoubleItem(locationCursor,"LATITUDE");
        double longitude = dbHandler.fetchDoubleItem(locationCursor,"LONGITUDE");


            Log.v("latitude",""+latitude);
            Log.v("latitude",""+longitude);     

            try {
                GpsUtils.writeFile(photoFile, latitude, longitude);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    }
    dbHandler.close();

    cameraHandler.startPreview();

解决方案

Ok, I struggled with this for a long time but finally got it. Last time I used it this code worked:

ExifInterface exif = new ExifInterface(imgFile.getCanonicalPath());
              //String latitudeStr = "90/1,12/1,30/1";
              double lat = location.getLatitude();
              double alat = Math.abs(lat);
              String dms = Location.convert(alat, Location.FORMAT_SECONDS);
              String[] splits = dms.split(":");
              String[] secnds = (splits[2]).split("\\.");
              String seconds;
              if(secnds.length==0)
              {
                  seconds = splits[2];
              }
              else
              {
                  seconds = secnds[0];
              }

              String latitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";
              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitudeStr);

              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, lat>0?"N":"S");

              double lon = location.getLongitude();
              double alon = Math.abs(lon);


              dms = Location.convert(alon, Location.FORMAT_SECONDS);
              splits = dms.split(":");
              secnds = (splits[2]).split("\\.");

              if(secnds.length==0)
              {
                  seconds = splits[2];
              }
              else
              {
                  seconds = secnds[0];
              }
              String longitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";


              exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitudeStr);
              exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, lon>0?"E":"W");

              exif.saveAttributes();

          }