2016-06-01 1 views
2

위치의 시차, 분, 초를 알고있는 경우 ExifInterface.TAG_GPS_LATITUDEExifInterface.TAG_GPS_LONGITUDE의 유효한 위치로 어떻게 변환합니까? 학위/분/초를 유효한 EXIF ​​인터페이스 문자열로 변환

나는 다음과 같은 발견 https://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_LATITUDE

을하지만 내가 제대로 형식을 이해하고 있는지 확실하지 않습니다. 다음과 같이 쓰여 있습니다 :

문자열. 형식은 "num1/denom1, num2/denom2, num3/denom3"입니다.

각 값에 사용할 분수 ... 항상 1입니까? 코드 예제 다음처럼 :

String exifLatitude1 = degress+ "/1," + minutes + "/1," + seconds + "/1"; 
나는 종종 초 /1000와 문자열을 참조, 그래서 다음을 대신 위의 예 맞는지 잘 모르겠어요

:

String exifLatitude2 = degress+ "/1," + minutes + "/1," + seconds + "/1000"; 

사람이 말해 줄 수 , 어느 것이 맞습니까?

답변

2

작동 용액 내 밀리/1000

  • -79.948862된다
  • -79 도로 56 분, 55903 밀리 세컨드 (동일 55.903 초)
  • 79/1,56/1,55903/사용 1000

나는 79/1,56/1,56/1도 괜찮은지 확인하지 않았다.

은이 코드를 사용하고 있습니다 : 감사

public static boolean saveLatLon(File filePath, double latitude, double longitude) { 
    exif = new ExifInterface(filePath.getAbsolutePath()); 
    debugExif(sb, "old", exif, filePath); 

    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, convert(latitude)); 
    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, latitudeRef(latitude)); 
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, convert(longitude)); 
    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, longitudeRef(longitude)); 

    exif.saveAttributes(); 
} 

/** 
* convert latitude into DMS (degree minute second) format. For instance<br/> 
* -79.948862 becomes<br/> 
* 79/1,56/1,55903/1000<br/> 
* It works for latitude and longitude<br/> 
* @param latitude could be longitude. 
* @return 
*/ 
private static final String convert(double latitude) { 
    latitude=Math.abs(latitude); 
    int degree = (int) latitude; 
    latitude *= 60; 
    latitude -= (degree * 60.0d); 
    int minute = (int) latitude; 
    latitude *= 60; 
    latitude -= (minute * 60.0d); 
    int second = (int) (latitude*1000.0d); 

    StringBuilder sb = new StringBuilder(20); 
    sb.append(degree); 
    sb.append("/1,"); 
    sb.append(minute); 
    sb.append("/1,"); 
    sb.append(second); 
    sb.append("/1000,"); 
    return sb.toString(); 
} 

private static StringBuilder createDebugStringBuilder(File filePath) { 
    return new StringBuilder("Set Exif to file='").append(filePath.getAbsolutePath()).append("'\n\t"); 
} 

private static String latitudeRef(double latitude) { 
    return latitude<0.0d?"S":"N"; 
}