0
還在繼續處理Google Maps JavaScript API v3,所以請隨身攜帶。我正在像這樣動態添加標記:谷歌地圖JavaScript API v3動態infowindow
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「單擊」功能很好地工作。我現在想要做的是爲每個標記添加一個infowindow。 OK我從谷歌這樣的代碼應該/不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]
的信息窗口?
在此先感謝