从外部点击javascript打开多个infowindow

时间:2012-12-28 11:24:42

标签: javascript google-maps infowindow

您好我正在使用谷歌地图显示我的搜索位置,在地图下方列出了搜索结果。如果用户点击以下结果,谷歌地图会显示信息窗口。

function setMarkers(map, locations) 
{
        var infoWindow = new google.maps.InfoWindow({});
        var markers = new Array(); 
        var image = new google.maps.MarkerImage('images/pin_red.png',
            new google.maps.Size(32,39),
            new google.maps.Point(0,0),
            new google.maps.Point(18, 30));

        var shape = {
            coord: [1, 1, 1, 20, 18, 20, 18 , 1],
            type: 'poly'
        };


        var alph    =   65;


        for (var i = 0; i < locations.length; i++) {

          var beach = locations[i];
          var myLatLng = new google.maps.LatLng(beach[1], beach[2]);

          var title =   beach[0].split('~~');

         var marker = new google.maps.Marker({
              position: myLatLng,
              map: map,
              icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+String.fromCharCode(alph)+'|FF0000|000000',
              shape: shape,
              title: title[0]+'<br>'+title[1],
              zIndex: beach[3]
          });


           $('#mappoint-'+String.fromCharCode(alph)).bind('click', function() {
                    google.maps.event.trigger(marker, 'mouseover')
            });

            google.maps.event.addListener(marker, 'mouseover', function() {

               infoWindow.setContent(this.title);
               infoWindow.open(map, this);
          });


         alph   =   parseInt(alph)+1;

       }
}

这是我正在使用的功能,它显示最后创建的infowindow,同时点击任何结果,任何人都有任何想法?

$('#mappoint-'+String.fromCharCode(alph)).bind('click', function() {
     google.maps.event.trigger(marker, 'mouseover')
});

此部分有问题,这只会绑定最后创建的标记。

0 个答案:

没有答案