1

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

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;

       }
}

这是我正在使用的功能,它在单击任何结果时显示最后创建的信息窗口,有人知道吗?

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

这部分有问题,这仅绑定到最后创建的标记。

4

0 回答 0