GPS 정보를 String으로 변경 ( double -> stirng : 도,분,초 )
public String ConvertTagGPSFormat(double coordinate)
{
String
strlatitude = Location.convert(coordinate,
Location.FORMAT_SECONDS);
String[] arrlatitude =
strlatitude.split(":");
StringBuilder sb = new
StringBuilder();
sb.append(arrlatitude[0]);
sb.append("/1,");
sb.append(arrlatitude[1]);
sb.append("/60,");
sb.append(arrlatitude[2]);
sb.append("/3600");
return
sb.toString();
}
String 값을 double형으로 변경하기 ( stirng : 도,분,초 -> double )
public Float convertToDegree(String stringDMS)
{
Float result =
null;
try
{
stringDMS = stringDMS.replace("/1,",
":");
stringDMS = stringDMS.replace("/60,", ":");
stringDMS =
stringDMS.replace("/3600", "");
Double FloatS =
Location.convert(stringDMS);
result = new Float( (FloatS)
);
}
catch (Exception e)
{
// TODO: handle
exception
Log.d("GPSManager ","convertToDegree :" +
e.getMessage());
}
return result;
}
위에 두 함수를 이용하여 해당값으로 변경한 후 저장 및 읽기에 사용한다.
1. JPG 태그에 저장
GPSManager gpsManager = GPSManager.getInstance();
String strlatitude =
gpsManager.ConvertTagGPSFormat(m_nlatitude);
String strlongtude =
gpsManager.ConvertTagGPSFormat(m_nlongtitude);
ExifInterface exif =
new
ExifInterface(strFullPath);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
strlatitude );
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,strlongtude
);
exif.saveAttributes();
저장할때는 도,분,초 형태로 구분된 String 타입을 사용한다.
2. JPG 태그로 부터 GPS정보 읽어오기
ExifInterface exif = new ExifInterface(file.getPath());
String strlatitude
= getTagString(ExifInterface.TAG_GPS_LATITUDE, exif);
String strlongtude =
getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif);
GPSManager gpsManager = GPSManager.getInstance();
double nlatitude =
gpsManager.convertToDegree(strlatitude);
double nlongtude =
gpsManager.convertToDegree(strlongtude);
String으로 읽어온 후 double 형으로 변경하여 해당 GPS 정보를 사용하면 된다.
간단한 내용이지만, 인터넷에서 찾기 힘들어 이틀정도 헤맸다.
'Development > Android' 카테고리의 다른 글
퀄컴 증강현실 SDK (0) | 2010.11.04 |
---|---|
Google Chrome to Phone (0) | 2010.10.26 |
Android Release Key 구하기 (0) | 2010.10.22 |
구글 맵 API Key 얻기 (0) | 2010.10.05 |
JPG에 Exif태그를 사용하여 GPS정보를 저장 및 읽기 (0) | 2010.10.05 |
카메라 프리뷰가 좌측으로 90도 회전 되어 나오다 (0) | 2010.10.05 |