지도상의 많은 마커 중 하나를 클릭하면 Google지도가 생성하는 infobox 내에 jquery의 $('#divname')
을 사용하여 <div>
을 선택하려고합니다.Google Maps InfoBox에서 Div에 액세스하는 방법?
문제 : 마커를 클릭 한 후 $("#gallery")
을 사용하여 div에 액세스하려고하면 해당 마커의 클릭 이벤트 리스너 내부에서 아무 일도 일어나지 않습니다. 해당 div에 포함 된 html을 클릭 수신기에서 console.log($("#gallery").html())
을 사용하여 가져 오려고 시도했지만 null
을 반환합니다 !! 이 div를 어떻게 선택할 수 있습니까?
이벤트 리스너 코드 조각 코드를 클릭
// Create Listeners
markers[i]._index = i;
google.maps.event.addListener(markers[i], 'click', function() {
infoboxes[this._index].open(map, markers[this._index]);
infoboxes[this._index].show();
console.log($('#gallery').html());
});
인포 박스 발췌문 코드에서
for(i = 0; i < json.length; i++) {
// Place markers on map
var latLng = new google.maps.LatLng(json[i].lat, json[i].lng);
var marker = new google.maps.Marker({
position: latLng,
map: map
});
markers.push(marker);
// Create infowindows
var boxText = '<div id="infobox"> \
<div id="infobox_header_title"> \
<span id="infobox_header_price">$' + json[i].price + '</span> \
<span id="infobox_header_room">' + json[i].bedroom + 'br </span> \
<span id="infobox_header_address">' + json[i].address_1 + '</span> \
</div> \
<div id="gallery"> \
<img src="images/cl/' + json[i].photos[0] + '.jpg" /> \
<img src="images/cl/' + json[i].photos[1] + '.jpg" /> \
</div> \
</div>';
var infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-140, 0),
zIndex: null,
boxStyle: {
},
closeBoxMargin: "10px 2px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: true,
pane: "floatPane",
enableEventPropagation: false
};
var infobox = new InfoBox(infoboxOptions);
infoboxes.push(infobox);
//<Click Event Listener code comes in here>