카카오 지도 코드

나고수·2022년 5월 2일
0

1일1공부

목록 보기
30/67

원하는 좌표에 마커 만들기

val mapPOIItem = mutableListOf<MapPOIItem>()
mapPOIItem.add(getMapPOIItem("ㅌㅅㅌ", 35.86401751026963, 128.6485239265323))
mapPOIItem.add(getMapPOIItem("ㅌㅅㅌ", 35.85881638638933, 128.6356195137821))
mapView.addPOIItems(mapPOIItem.toTypedArray())

맵뷰 세팅

MapView.setMapTilePersistentCacheEnabled(true) //한번 로딩 된 지도는 캐시에 저장해놓고 빠르게 로딩하기 
mapView = MapView(activity)
binding.mapViewContainer.addView(mapView)
mapView.setZoomLevel(2, true)
mapView.setMapViewEventListener(this) //지도클릭.드래그 등 리스너
mapView.setCurrentLocationEventListener(this)//현재 위치가 바뀌는 이벤트가 발생할때마다 응답을 받는 리스너
mapView.setCustomCurrentLocationMarkerImage(R.drawable.ic_my_location, MapPOIItem.ImageOffset(108, 0)) //현재위치 마커
mapView.setCustomCurrentLocationMarkerTrackingImage(R.drawable.ic_my_location, MapPOIItem.ImageOffset(108, 0)) //현재위치 트래킹 마커

현재위치에서 주소 받아오는 함수

private fun getJusoFromGeoCord(mapPoint: MapPoint?) {
    mapPoint?.let {
        val currentMapPoint = MapPoint.mapPointWithGeoCoord(mapPoint.mapPointGeoCoord.latitude, mapPoint.mapPointGeoCoord.longitude) //현재위치
        MapReverseGeoCoder(BuildConfig.appKey, currentMapPoint, object : MapReverseGeoCoder.ReverseGeoCodingResultListener {
            override fun onReverseGeoCoderFoundAddress(p0: MapReverseGeoCoder?, address: String) {
		//주소받아 오기 성공 - address: 현재 주소
            }

            override fun onReverseGeoCoderFailedToFindAddress(p0: MapReverseGeoCoder?) {
		//주소 받아오기 실패 
                toast("주소를 찾을 수 없습니다.")
            }
        }, activity).startFindingAddress()
    }
}

카카오지도 api

profile
되고싶다

0개의 댓글