마커에 새로운 프로퍼티 추가가 가능할까요?

[FAQ] 지도/로컬 API 문의 전 꼭 읽어 주세요.

현재 next.js 애플리케이션에 카카오맵 api 사용중이고, 카카오맵 타입 관련해서 라이브러리를 사용하고 있습니다.(kakao.maps.d.ts)

현재 진행중인 서비스가, 첫 지도 로딩 시 서버에서 가져온 정보를 반복문을 돌며 마커에 연결시켜야하는데, 따로 프로퍼티를 마커에 부여할 수 있는 방법이 있는지 궁금합니다.

현재 대안으로 setTitle에 정보를 저장하고 getTitle로 정보를 사용하는데, 문제는 마우스를 호버하면 툴팁이 떠서 저장한 정보가 노출이 되고 있습니다. 그래서 새로운 방법을 아예 찾고자 질문을 드립니다.

별도로 속성을 추가하는 기능은 제공하고 있지 않습니다.
맵핑 테이블을 활용해서 마커와 데이터 정보를 관리하는 방법도 있으니 참고 부탁드립니다.

let items = {
    'id1': {marker: marker, data: /*….*/}, 
    'id2': {marker: marker, data: /*….*/}, 
    /* … */
}

답변 감사합니다. 참고해서 적용해보겠습니다.

Hello, @신명희1281

Managing Multiple Markers with an Array If you use multiple markers on the map, you can add custom data to it and store it in an array.

const markers = [];

const locations = [
    { lat: 37.5665, lng: 126.9780, name: "Seoul", description: "Seoul," },
    { lat: 35.1796, lng: 129.0756, name: "Busan", description: "Busan" }
];

locations.forEach((location, index) => {
    const marker = new kakao.maps.Marker({
        position: new kakao.maps.LatLng(location.lat, location.lng)
    });

    // Add custom data to the marker
    marker.customData = {
        id: index,
        name: location.name,
        description: location.description
    };

    markers.push(marker); // Add markers to the array

    // Display marker information when clicked
    kakao.maps.event.addListener(marker, 'click', function() {
        console.log("Selected Marker Information:", marker.customData);
    });
});

i I hope this is useful to you.

Wow. Thank you so much…! Thanks to you, I was able to solve this problem… You’ve been such a huge help. THANK YOU !

Hello, I’m glad I could help. If you have any questions, tag me and I’ll help you.

@신명희1281
If you want to add more details, write what you want to add here and I will send you a new code.

Thank you so much for being so helpful and supportive! Everything is working great now. I truly appreciate your kindness in offering further assistance! :+1:

I enjoy helping people in my free time. If you need support about Kakao and other Korean infrastructure providers, I’m here. I wish you a good weekend. 나중에 봐요:wave::wave::blush:

I hope you have a great weekend as well ! Thank you !! :grinning: