0

我正在像这样动态添加标记:

var oldMarkers = null;
    return function(map, locations){
        //Clearing markers, if they exist
        if(oldMarkers && oldMarkers.length !== 0){
            for(var i = 0; i < oldMarkers.length; ++i){
                oldMarkers[i].setMap(null);
            }
        }
        //Adding new markers
        oldMarkers = [];
        for (var i = 0; i < locations.length; i++) {
            var newmarker = locations[i];
            var myLatLng = new google.maps.LatLng(newmarker[1], newmarker[2]);
            var marker = new google.maps.Marker({
               position: myLatLng,
               map: map,
               shape: shape,
               title: newmarker[0],
               zIndex: newmarker[3],
               clickable: true
            });
oldMarkers.push( marker );
 }

基于 jQuery“点击”功能运行良好。我现在想做的是为每个标记添加一个信息窗口。好的,我有这个来自谷歌的代码,应该/确实在之前oldMarkers.push( marker )

var j = i + 1;
marker.setTitle(j.toString());
attachSecretMessage(marker, j);

这个功能:

function attachSecretMessage(marker, number) {
  var message = ["This","is","the","secret","message"];
  var infowindow = new google.maps.InfoWindow(
      { content: message[number],
        size: new google.maps.Size(50,50)
      });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

它有点工作,因为信息框出现了 2 个应该做的标记,但不是全部。这是我不明白的地方/地方:如果我有一个数组来制作这样的新标记(仅作为示例):

var essentials = [
['Marker 1', 12.254181, 12.649962 , 9],
['Marker 2', 12.254181, 12.649962 , 9],
['Marker 3', 12.254181, 12.649962 , 9],
['Marker 4', 12.254181, 12.649962 , 9],
}

我需要/想要做的是为信息窗口的内容添加一个数组键,有点像这样:

 var essentials = [
    ['Marker 1', 12.254181, 12.649962 , 9, 'Info Window content']

我如何传递newmarker[4]到信息窗口?

4

1 回答 1

1

天哪,我在想!- 只需添加 attachSecretMessage ( marker, newmarker[4] );哎呀!正如所说的厚!对不起

于 2012-05-17T10:06:05.250 回答