Infobubble Keep添加选项卡,不删除添加的上一个选项卡

时间:2013-12-03 07:47:48

标签: javascript jquery asp.net-mvc-3 google-maps google-maps-api-3

enter image description here我遇到了这个问题,而且我刚接触使用Infobubble for Google Maps,当我点击标记并添加标签时,当我更改标记时点击了上一个标签仍然显示 我想要的只是删除上一个标签。

这是我的代码段:

 function codeAddress() {
        infoBubble = new InfoBubble({
            map: map,
            shadowStyle: 0,
            padding: 10,
            borderRadius: 10,
            arrowSize: 15,
            maxWidth: 300,
            borderWidth: 1,
            borderColor: '#ccc',
            arrowPosition: 30,
            arrowStyle: 0
        });
        $.getJSON('/Dashboard/LoadWorkerList', function (address) {
            $.each(address, function () {
                var currVal = this["AddressLine1"];
                var Name = this["Name"];
                var Gender = this["Gender"];
                var Bdate = this["Birthdate"];
                geocoder.geocode({ 'address': currVal }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var marker = new google.maps.Marker({
                            map: map,
                            icon: iconBase + 'man.png',
                            position: results[0].geometry.location,
                            title: currVal

                        })

                        $('#places').append($('<li>')
                                    .text(currVal)
                                    .data('location', results[0].geometry.location));

                        google.maps.event.addListener(map, 'bounds_changed', function () {
                            $('#places li').css('display', function () {
                                return (map.getBounds().contains($(this).data('location')))
                      ? ''
                      : 'none';
                            });
                        });

                        //mgr = new MarkerManager(map);


                        google.maps.event.addListener(marker, 'click', (function (marker, i) {
                            return function () {
                                infoBubble.addTab(Name, Name + "" + currVal + "" + Gender + "" + Bdate);
                                infoBubble.open(map, marker);
                            }
                        })(marker, currVal));
                        address.push(marker);

                    }
                    else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
                        setTimeout(codeAddress, 2000);
                    }
                    else {
                        alert("Geocode was not successful for the following reason: " + status);
                    }
                });
            });
            google.maps.event.trigger(map, 'bounds_changed');
        });
    }

如你所见。布兰妮斯皮尔斯的标签就在麦莉赛勒斯的标记上。 我想要的是删除第一个单击标记选项卡

1 个答案:

答案 0 :(得分:0)

为什么不尝试这样的东西,而不是每次都向一个infowindow添加标签并更改它的位置?

var myLatlng = new google.maps.LatLng(latValue, longValue);
var mapOptions = {
  ...
  center: myLatlng
};

var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var infoBubble = null;

...

google.maps.event.addListener(marker, 'click', function() {
    if (infoBubble) {
        infoBubble.close();
    }
    infoBubble = new google.maps.InfoWindow({content: singersTextContent});
    infoBubble.open(map, marker);
    ...
});