Javascript Google Map USGSOverlay clickevent在同一级别标记上的多响应

Javascript Google Map USGSOverlay clickevent在同一级别标记上的多响应,javascript,android,google-maps,google-maps-api-3,Javascript,Android,Google Maps,Google Maps Api 3,我使用GoogleMapV3创建了20个标记,单击一个标记,标记将显示它的信息窗口(标记、信息窗口都是由USGSOverlay创建的) 现在,我得到一个bug,例如: 我单击了标记A,并显示了信息窗口B,在这里我将单击信息窗口B转到另一个页面,但是现在,标记C(在信息窗口B下)也得到了clickenvent,并显示它的信息窗口D 为什么??我试着阻止我的动作,但是努斯 function makeInfoWindow(item){ var marker= new USGSOverlay(g

我使用GoogleMapV3创建了20个标记,单击一个标记,标记将显示它的信息窗口(标记、信息窗口都是由USGSOverlay创建的)

现在,我得到一个bug,例如:

我单击了标记A,并显示了信息窗口B,在这里我将单击信息窗口B转到另一个页面,但是现在,标记C(在信息窗口B下)也得到了clickenvent,并显示它的信息窗口D

为什么??我试着阻止我的动作,但是努斯

function makeInfoWindow(item){
    var marker= new USGSOverlay(getLargeView(item),item.getLatLng(),{x:-56,y:-118},'infobox',item.id);
    mGmap.addOverlay('infobox',marker);
    marker.bind("click",function(event){
        event.cancelBubble = true;
        if (event.stopPropagation) {
            event.stopPropagation();
        }
        console.log("InfoWindow click ");
    });
    return marker;
}

USGSOverlay.prototype.bind = function (eventname, callback) {
    this.clickListener=callback;
    google.maps.event.addDomListener(this.htmlObj_, eventname, this.clickListener);
}
我认为markers和infowindos处于同一水平,所以他们得到了相同的clickevent,我为此花了很多时间,有人帮我吗

//marker
function makePointMarker(item){
    var marker = new google.maps.Marker({
        position: item.getLatLng(),
        map: mGmap._map,
        draggable: false,
        icon: getPointIcon(item)
    });

    //infowindow
    if(item.infoWindow == null){
        item.infoWindow=makeInfoWindow(item);
        item.infoWindow.hide();
    }

    // register marker clickevent
    google.maps.event.addDomListener(marker, 'click', function() {
        //event.stopPropagation();
        // event.cancelBubble = true;
        if(mSelectedItem!=null){
            if(mSelectedItem.id==item.id){
                if(mSelectedItem.infoWindow.isShow()){
                    mSelectedItem.infoWindow.hide();
                    console.log("hide");
                }else{
                    mSelectedItem.infoWindow.show();
                    console.log("show");
                }
                refreshMap();
                window.gsMapNative.onMarkerClicked(mSelectedItem.infoWindow.isShow(),item.id,item.name,item.isMainPoi,item.poiType,item.mapType,item.inChina);
                return;
            }else{ 
                mSelectedItem.infoWindow.hide();
                mSelectedItem.infoWindow=null;
                mSelectedItem=null;
            }
        }

        console.log("create new !");
        mSelectedItem=item;
        mSelectedItem.infoWindow=makeInfoWindow(item);
        mSelectedItem.infoWindow.show();
        refreshMap();
        window.gsMapNative.onMarkerClicked(mSelectedItem.infoWindow.isShow(),item.id,item.name,item.isMainPoi,item.poiType,item.mapType,item.inChina);

        return true;
    });
    return marker;
}

我以前遇到过这个问题,并使用markerOption infoWindowIndex修复了这个问题。因此,将所有20个infowindow放在一个全局数组列表中,对于每个标记,通过如下指定索引来指定infowindow

var marker = new google.maps.Marker({
        position: item.getLatLng(),
        map: mGmap._map,
        draggable: false,
        icon: getPointIcon(item),
        infoWindowIndex : index    //* <- make sure this index points to the correct info window
    });
var marker=new google.maps.marker({
位置:item.getLatLng(),
地图:mGmap.\u地图,
可拖动:错误,
图标:getPointIcon(项目),

infoWindowIndex:index/*我可能需要向您展示如何在listner函数中使用infoWindowIndex,请查看更新的答案谢谢您的帮助!您的答案我不清楚。但我找到了另一种方法:我以前使用new google.maps.Marker创建了标记,
var Marker=new google.maps.Marker({position:item.getLatLng(),map:mGmap.\u map,draggable:false,icon:getPointIcon(item),infoWindowIndex:index/*当我使用这个var标记时=新的USGSOverlay(getPointView(item),item.getLatLng(),{x:-21,y:-58},'infobox',item.id);
然后单击的事件是正确的!我认为标记和信息窗口现在在同一个根对象上,我将在添加信息窗口索引后研究您的答案,然后?对象mSelectedItem是全局信息窗口项。所有标记使用一个信息窗口。