日安!我只想问一下InfoBubble是否可以有一个监听器。我尝试在div中插入InfoBubble的文本,并在其中插入onclick命令,但没有任何反应。
提前谢谢。顺便说一下,我目前正在开发一个android应用程序,并使用webview来显示地图。
发布于 2012-07-27 18:31:56
好了,jetpro
下面是我在使用javascript的类似场景中所做的事情:
/* json data object requires:
data.Id,
data.Lat,
data.Lng,
data.Name,
data.Address,
data.Date
*/
function DisplayMapEvent(data, targetDiv) {
var latlng, options, map, contentString, infowindow, marker;
// setup our variables
latlng = new window.google.maps.LatLng(data.Lat, data.Lng);
options =
{
zoom: 15,
center: latlng,
mapTypeId: window.google.maps.MapTypeId.ROADMAP
};
// create the map inside our map <div> and apply the options
map = new window.google.maps.Map(document.getElementById(targetDiv), options);
map.setOptions(options);
// info to display in the infowindow popup
contentString =
'<div>' +
'<b style="color: #DC6852;">' + data.Name + '</b><br />' +
'Where: ' + data.Address + '<br />' +
'When: ' + data.Date + '<br />' +
'</div>';
// info/marker and popup objects setup
infowindow = new window.google.maps.InfoWindow({
content: contentString
});
marker = new window.google.maps.Marker({
position: latlng,
map: map
});
// add the usual suspect event handlers
window.google.maps.event.trigger(map, 'resize');
// to allow us to repoen a map marker infowindow if closed
window.google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
// open infowindow on map once rendered
infowindow.open(map, marker);
// sit back and wonder at the glory of google maps mow :-)
}在我的示例中,我将一个json对象传递给DisplayMapEvent函数,但您可以根据自己的需求重新组合此对象。每当我想要在我的地图上添加一个新的标记时,这个函数就会被调用,所以你可以根据需要提升这个批发式和重构。
希望这能有所帮助。
发布于 2012-12-29 02:35:26
像这样添加监听器
google.maps.event.addDomListener(infoBubble2.bubble_, 'click', function(){..});玩得开心!
https://stackoverflow.com/questions/11685719
复制相似问题