마커에서 클릭 이벤트에 대한 Google지도 리스너를 만들려고합니다. 문제는 이벤트가 실행되지 않는다는 것입니다. 아래 코드는 맵을 초기화하고 맵에 마커를 추가하는 방법을 보여줍니다. 나는 이벤트 리스너가 초기화에 추가되어야한다고 생각한다.Google지도 마커 클릭 이벤트가 실행되지 않음
//initializing my variables
var marker = []; //final markers that wil go on the map
//this function loads the map on to the page.
function initialize() {
var mapOptions = {
center: {
lat: 0,
lng: 0
},
zoom: 2
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
//listener for clicks on markers
google.maps.event.addListener(marker, 'click', markerClick);
//listener that listens for the map to load before calling the drop function
google.maps.event.addListenerOnce(map, 'tilesloaded', function() {
//this part runs when the mapobject is created and rendered
google.maps.event.addListenerOnce(map, 'idle', function() {
//this part runs when the mapobject shown for the first time
drop();
});
});
}
//drop function
function drop() {
for (var i = 0; i < pictureLocations.length; i++) {
setTimeout(function() {
addMarker();
}, i * 200);
}
}
//add marker function
function addMarker() {
marker.push(new google.maps.Marker({
position: pictureLocations[iterator],
map: map,
draggable: false,
animation: google.maps.Animation.DROP,
id: iterator
}));
iterator++;
}
마커를 클릭해도 아무런 변화가 없습니다. 클릭 기능에서 자바 스크립트 경고를 발생시키는 경고 메시지가 표시됩니다.
물건의 순서를보세요. Listner를 추가하면 마커가 아직 존재하지 않습니다. 또한 마커는 마커 배열에 대한 끔찍한 이름입니다. 그것은 끔찍하게 혼란 스럽습니다. –
[Google지도 JS API v3 - 단순 다중 마커 예] 중복 될 수 있음 (http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example) – geocodezip
아마 wouldn [문서의 예] (https://developers.google.com/maps/documentation/javascript/infowindows#open)를 보니 상처가 없습니다. – geocodezip