Front-end/HTML

마커에 infoView표시하기

Lyla. 2024. 3. 1. 23:19

function createMarker(labelContent, lat, lng) {
            var markerOptions = {
                position: new naver.maps.LatLng(lat, lng),
                map: map
            };

            var marker = new naver.maps.Marker(markerOptions);

            var contentString = [
                '<div class="iw_inner">',
                '   <h3>마커 정보</h3>',
                '   <p>마커 내용: ' + labelContent + '<br>',
                '       좌표: ' + lat + ', ' + lng + '</p>',
                '</div>'
            ].join('');

            var infowindow = new naver.maps.InfoWindow({
                content: contentString
            });

            naver.maps.Event.addListener(marker, 'click', function (e) {
                if (infowindow.getMap()) {
                    infowindow.close();
                } else {
                    infowindow.open(map, marker);
                }
            });
        }