본문 바로가기
프로그래밍/Android

[Android] 카카오맵 마커 클릭이벤트, 위도경도 구하기

by Youngs_ 2022. 9. 18.
poiItem.mapPoint.mapPointGeoCoord // 위도, 경도 구하는 코드

 

MainActivity.kt

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import net.daum.mf.map.api.MapPOIItem
import net.daum.mf.map.api.MapPoint
import net.daum.mf.map.api.MapView

...
lateinit var mapView : MapView

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater,null,false)
    setContentView(binding.root)
    mapView = MapView(this)

    mapView.setCalloutBalloonAdapter(CustomBalloonAdapter(layoutInflater))

    val mapViewContainer = binding.frameLayout

    mapViewContainer.addView(mapView)
    
}

CustomBalloonAdapter.kt

import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import net.daum.mf.map.api.CalloutBalloonAdapter
import net.daum.mf.map.api.MapPOIItem

class CustomBalloonAdapter(inflater: LayoutInflater): CalloutBalloonAdapter {
    val mCalloutBalloon: View = inflater.inflate(R.layout.balloon_layout, null)
    val name: TextView = mCalloutBalloon.findViewById(R.id.ball_tv_name)
    val address: TextView = mCalloutBalloon.findViewById(R.id.ball_tv_address)

    override fun getCalloutBalloon(poiItem: MapPOIItem?): View {
        // 마커 클릭 시 나오는 말풍선
        name.text = poiItem?.itemName   // 해당 마커의 정보 이용 가능
        address.text = "getCalloutBalloon"
        poiItem.mapPoint.mapPointGeoCoord // 위도, 경도 구하는 코드
        return mCalloutBalloon
    }

    override fun getPressedCalloutBalloon(poiItem: MapPOIItem?): View {
        // 말풍선 클릭 시
        address.text = "getPressedCalloutBalloon"
        return mCalloutBalloon
    }
}

출처 : https://daily50.tistory.com/210

 

댓글