[안드로이드 스튜디오 코틀린] LocationRequest.create() deprecated 대응
https://developer.android.com/training/location/change-location-settings?hl=ko
위치 설정 변경 | Android 개발자 | Android Developers
위치 설정 변경 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 앱에서 위치를 요청하거나 권한 업데이트를 수신해야 한다면 기기는 GPS 또는 Wi-Fi 검색과 같
developer.android.com
주소 위치를 받아 오기 위해 location을 사용하고 싶다. 이 때 같은 주기로 위치를 갱신하고 싶어 locationRequest를 사용하기로 했다.
그런데
LocationRequest.create()
가 deprecated 되었다.
LocationRequest.PRIORITY_HIGH_ACCURACY
interval 값을 주어 원하는 주기만큼 위치를 갱신시켜 주고 싶을 때 사용한다.
위의 공식 사이트에도
val locationRequest = LocationRequest.create()?.apply {
interval = 10000
fastestInterval = 5000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
이처럼 사용한다고 나와있는데,
사용할 수가 없다.
https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest
LocationRequest | Google Play services | Google Developers
developers.google.com
왜 이렇게 다 경고가 뜨는지.. 누가 android 사이트 수정 좀..
그렇다면 방법은 Builder를 사용해야 한다.
LocationRequest.Builder | Google Play services | Google Developers
developers.google.com
여기서 참고하여서 사용해야 하고,
사용법은
private lateinit var locationRequest: LocationRequest
locationRequest = LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 5000)
.apply {
setMinUpdateIntervalMillis(5000)
setMaxUpdateDelayMillis(5000)
setGranularity(Granularity.GRANULARITY_PERMISSION_LEVEL)
setWaitForAccurateLocation(true)
}.build()
위처럼 사용하면 된다.
참고 사이트
https://tomas-repcik.medium.com/locationrequest-create-got-deprecated-how-to-fix-it-e4f814138764
LocationRequest.create() got deprecated. How to fix it?
How to properly ask for location in location services 21.0.0
tomas-repcik.medium.com