不要用自定义标记打开infoWindow。 (谷歌地图)

时间:2016-10-24 10:07:57

标签: google-maps infowindow

我需要在infoWindow上打开customMarker

InfoWindow没有打开。 "单击"没有工作:

$google.maps.event.addDomListener(overlay, 'click', function () {
        console.log("test");
        iw.open(map, this);
        });

这是我的代码:

$.getJSON(jsonShops, function(places) {
    for (var i = 0, index = 0; i < places.shops.length; i++, index++) {
        var bounds = new google.maps.LatLng(places.shops[i].lat, places.shops[i].lng);
        var overlay = new MarkerSOverlay(bounds, alphabet.charAt(index), map);

        var iw = new google.maps.InfoWindow({
            content: "Simple",                
            position: bounds
        });


        google.maps.event.addDomListener(overlay, 'click', function () {
            console.log("test");
            iw.open(map, this);
        });
}

1 个答案:

答案 0 :(得分:1)

addDomListener更改为addListener

google.maps.event.addListener(overlay, 'click', function () {
   console.log("test");
   iw.open(map, this);
});

addListener适用于google.maps对象(如标记),addDomListener适用于DOM节点。