inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

junmo lee님의 게시글

junmo lee junmo lee

@junmoyo

수강평 작성수
9
평균평점
4.4

게시글 1

질문&답변

geoCoder.getFromLocation 에러

private fun updateUI(){ locationProvider = LocationProvider(this@MainActivity) var latitude : Double? = locationProvider.getLocationLatitude() var longitude : Double? = locationProvider.getLocationLongitude() if(latitude != null || longitude != null){ //1. 현재 위치를 가져오고 UI를 Update val address = getCurrentAddress(latitude!!, longitude!!) address?.let{ binding.tvLocationTittle.text = "${it.thoroughfare}" binding.tvLocationSubtittle.text = "${it.countryName} ${it.adminArea}" } //2. 미세먼지 농도 가져오고 UI를 Update }else { Toast.makeText(this,"위도, 경도 정보를 가져올 수 없습니다.",Toast.LENGTH_LONG).show() } } private fun getCurrentAddress(latitude : Double, longitude : Double) : Address?{ val geocoder = Geocoder(this, Locale.KOREA) val addresses : List try { addresses = geocoder.getFromLocation(latitude, longitude, 7)!! }catch (ioException : IOException){ Toast.makeText(this,"geocoder 서비스를 이용불가 합니다.",Toast.LENGTH_LONG).show() return null }catch (illegalArgumentException : java.lang.IllegalArgumentException){ Toast.makeText(this,"잘못된 위도, 경도 입니다.",Toast.LENGTH_LONG).show() return null } if(addresses == null || addresses.size == 0){ Toast.makeText(this,"주소를 찾을 수 없습니다.",Toast.LENGTH_LONG).show() return null } return addresses[0] }

좋아요수
0
댓글수
2
조회수
569