I've been trying to add infowindows to my markers and I'm stuck since the avaible SO answers are pretty old. I have this code that corresponds to this answer in SO:
var map_center = new google.maps.LatLng(-0.179041, -78.499211);
var map = new google.maps.Map(document.getElementById('mapa_ciudad'),
mapOptions);
marker_objects = [];
for (i = 0; i < markers.length; i++){
marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[i][1], markers[i][2]),
map : map,
title: markers[i][0]
});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, "click", function(marker){
// !!! PROBLEM HERE
return function(){
var content = [marker.title];
infowindow.setContent(content);
infowindow.open(map, marker);
}
})(marker);
marker_objects.push(marker);
}
function AutoCenter(){
var bounds = new google.maps.LatLngBounds();
$.each(marker_objects, function(index, marker){
bounds.extend(marker.position)
});
map.fitBounds(bounds);
}
AutoCenter();
I get the error TypeError: google.maps.event.addListener(...) is not a function