title: Android write EXIF GPS Latitude and Longitude onto JPEG failed
body: <p>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 !</p>
  
  <p>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.</p>
  
  <p>I use EXIF Viewer in Firefox to see the result.  </p>
  
  <p>Does the position for the IO Exception matters?</p>
  
  <p>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</p>
  
  <pre><code> 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();
  
      }
  
  }
  </code></pre>
  
  <p>The below is the position to call the method
  ...</p>
  
  <pre><code>    Cursor locationCursor = dbHandler.fetchGpsLocationTypeByAttendInfoID(attendInfoId);
        if (locationCursor.getCount()&gt;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();
  </code></pre>