일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- notification setting
- shotcut
- webview
- Android
- jsontokotlinclass
- notification bar
- BottomSheetDialog
- room
- datastore
- 이미지 gps
- prettyJson
- ActivityResultContracts
- onResume
- application
- App Startup
- itemAnimator
- Plugins
- LOG
- skipcollapsed
- kdoc-generator
- Git
- notification
- Blinking
- ExifInterface
- onReceivedSslError
- requestPermission
- ChromeCustomTab
- 403 Error
- circlecrop
- navigation component
- Today
- Total
Debbi Story
ExifInterface 이미지 위치정보 가져오기 본문
안녕하세요. 카메라앱 설정에서 위치 태그를 설정해두면 사진 촬영시 위치 정보가 같이 저장되는데
이미지의 meta 정보중에서 위치 gps 값을 가져오는 방법을 소개합니다.
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface
ExifInterface | Android Developers
ExifInterface public class ExifInterface extends Object java.lang.Object ↳ androidx.exifinterface.media.ExifInterface This is a class for reading and writing Exif tags in various image file formats. Supported for reading: JPEG, PNG, WebP, HEIF, DNG
developer.android.com
먼저 import 할때 두가지가 나오는데
import android.media.ExifInterface
import androidx.exifinterface.media.ExifInterface
아래것으로 import를 해주시면 됩니다.
import androidx.exifinterface.media.ExifInterface
그리고 이미지의 Uri 값을 가지고 있다면 실제 파일의 경로로 변환해 줍니다.
fun uri2path(context: Context, contentUri: Uri): String? {
val proj = arrayOf(MediaStore.Images.Media.DATA)
val cursor: Cursor? = context.contentResolver.query(contentUri, proj, null, null, null)
cursor?.moveToNext()
val path = cursor?.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
val uri = Uri.fromFile(File(path))
cursor?.close()
return path
}
그리고 중요!
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
Manifest에 선언해 주시고 런타임시에 Manifest.permission.ACCESS_MEDIA_LOCATION 을 요청해주시면 됩니다.
val exif = ExifInterface(path)
exif.latLong?.get(0) // 위도 latitude
exif.latLong?.get(1) // 경도 longitude
ExifInterface 생성자에 위에서 얻은 파일 경로를 넣어주시고,
latLong은 double array 타입이고 첫번째가 위도, 두번째가 경도값 가져오기 성공!
'안드로이드 > Tip' 카테고리의 다른 글
[Android] 알림 설정 이동 하기! (0) | 2021.10.28 |
---|---|
Notification badge 설정하기! (0) | 2021.10.26 |
Glide circle 이미지에 테두리선 그리기 (0) | 2021.07.06 |
Navigation Component data전달하기 (0) | 2020.11.10 |
Custom Notification bar 만들기 (0) | 2020.10.28 |