谷歌地图API 3中的可点击信息气泡



您好!我只是想问一个InfoBubble是否可以有一个监听器。我试图在div中插入InfoBubble的文本,并在其中插入onclick命令,但什么也没发生。

提前谢谢。顺便说一句,我目前正在开发一个android应用程序,并使用webview来显示地图。

ok,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函数中,但您可以根据自己的需求重新调整它。每当我想在地图上添加一个新标记时,就会调用这个函数,这样你就可以根据需要进行大规模的提升和重构。

希望这能有所帮助。

添加类似的侦听器

google.maps.event.addDomListener(infoBubble2.bubble_, 'click', function(){..});

玩得开心!

最新更新