我有一张地图,我一直在试图找出将infoWindow添加到生存在数组中的标记并且卡住了..使用单个地图和单个标记,我可以添加信息窗口没问题。但是对于我的生活,我无法让infowindows在我的阵列中工作。如果任何人能够帮助我做到这一点,我会永远是伟大的。我的意图是能够在infowindows中拉动html。这里是我到目前为止的一个小提琴。将信息窗口添加到数组中的多个标记
var map;
var markers = [];
function initMap() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 14,
center: new google.maps.LatLng(-33.91721, 151.22630),
mapTypeId: 'roadmap',
disableDefaultUI: true
});
// var iconBase = <?php echo "'/images/markers/'"; ?>;
var icons = {
typea: {
icon: "http://maps.google.com/mapfiles/ms/micons/blue.png"
},
typeb: {
icon: "http://maps.google.com/mapfiles/ms/micons/green.png"
},
typec: {
icon: "http://maps.google.com/mapfiles/ms/micons/orange.png"
}
};
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map,
type: feature.type
});
marker.addListener('click', function() {
//set zoom level
map.setZoom(20);
//center map
map.setCenter(marker.getPosition());
alert("Testing");
});
markers.push(marker);
}
filterMarkers = function(getType) {
console.log(getType);
for (var i = 0; i < markers.length; i++) {
if (markers[i].type == getType || getType == "") {
markers[i].setVisible(true);
} else {
markers[i].setVisible(false);
}
}
}
var features = [{
position: new google.maps.LatLng(-33.91721, 151.22630),
type: 'typea'
}, {
position: new google.maps.LatLng(-33.91539, 151.22820),
type: 'typeb'
}, {
position: new google.maps.LatLng(-33.91747, 151.22912),
type: 'typec'
}];
for (var i = 0, feature; feature = features[i]; i++) {
addMarker(feature);
}
}
google.maps.event.addDomListener(window, "load", initMap);
完整的工作小提琴:http://jsfiddle.net/h80vtmye/
我没有在您发布的代码中看到infowindows的任何尝试。 – geocodezip
你说得对。我剔除了代码生成错误,希望能够描述我在做什么,希望有人能帮助我。无论如何,我得到它的工作。 – oompahlumpa