setMark 변경사항

sooj·2023년 10월 22일

.code

목록 보기
8/10

1


    private fun setMark(location: UserLocation) {
        val marker = Marker()
        // 마커 위치
        if (location != null) {
            marker.position = LatLng(location.latitude, location.longitude)
        }
        // 마커 우선순위
        marker.zIndex = 10
        // 마커 표시
        marker.map = naverMap
        // 원근감 표시
         marker.isIconPerspectiveEnabled = true
        // 마커의 투명도
        marker.alpha = 0.8f

        // 마커 이미지
        marker.icon = OverlayImage.fromResource(R.drawable.heart)

        marker.width = 130
        marker.height = 120

    }

2 (fail)

  1. 경로 잘못 설정
  2. 시도는 좋았으나..

    private fun setMark(location: UserLocation) {
        val marker = Marker()
        // 마커 위치
        if (location != null) {
            marker.position = LatLng(location.latitude, location.longitude)
        }
        // 마커 우선순위
        marker.zIndex = 10
        // 마커 표시
        marker.map = naverMap
        // 원근감 표시
         marker.isIconPerspectiveEnabled = true
        // 마커의 투명도
        marker.alpha = 0.8f

        marker.width = 130
        marker.height = 120

        // 파베 스토리지에서 이미지 다운로드
        val storageRef = FirebaseStorage
        .getInstance()
        .getReference("images/IMAGE_20231020_230927.png") 
        // 파베 스토리지 파일 참조
        val imageRef = storageRef.child("images/IMAGE_20231020_230927.png")
        Log.d("sooj", "받아짐 ? ${storageRef}")

       imageRef.getBytes(ONE_MEGABYTE).addOnSuccessListener {data ->
           // 데이터를 비트맵으로변환
           val bitmap = BitmapFactory.decodeByteArray(data,0, data.size)

           // 비트맵을 오버레이이미지로 변환
           val overlayImage = OverlayImage.fromBitmap(bitmap)

           // 마커 생성 및 설정
           val marker = Marker()
           marker.icon = overlayImage
       }
           .addOnFailureListener { }
    }

3 (Success !)

  1. 코일 -> 비트맵으로 변환

    private fun setMark(location: UserLocation) = lifecycleScope.launch {
        val marker = Marker()
        // 마커 위치
        if (location != null) {
            marker.position = LatLng(location.latitude, location.longitude)
        }
        // 마커 우선순위
        marker.zIndex = 10
        // 마커 표시
        marker.map = naverMap
        // 원근감 표시
         marker.isIconPerspectiveEnabled = true
        // 마커의 투명도
        marker.alpha = 0.8f

        marker.width = 130
        marker.height = 120

        val image = "https://firebasestorage.googleapis.com/v0/b/frompet-70b42.appspot.com/o/images%2FIMAGE_20231018_215401.png?alt=media&token=7353dc7b-f260-4ca9-b9ba-47ea95911b79"
        val imageLoader = context?.let { Coil.imageLoader(it) }
        val request = ImageRequest.Builder(requireContext()).data(image).target {
            val bitmap = (it as BitmapDrawable).bitmap
            val imageOverlay = OverlayImage.fromBitmap(bitmap)
            marker.icon = imageOverlay
        }.build()

        imageLoader?.execute(request)


    }
profile
하루하루는 성실하게 인생 전체는 되는대로

0개의 댓글