I have json objects infoCentros
, which I use to build maps, Like:
for (var i = 0; i & lt; infoCentros.length; i ++) {var centro = infoCentros [i]; Var lat = centro.cordenadas.lat; Var lon = centro.cordenadas.long; If (lat and lon) {c ++; Latlon = new google.maps.LatLng (lat, lon); Var Moption = {Venue: Laylan, Map: $ Project.gmap} moptions.icon = theme_uri + '/images/marker.png'; Var marker = new google.maps.Marker (moptions); $ Project.mapMarkers.push (marker); Google.maps.event.addListener (Marker, 'Click', function () {$ project.mapInfoWindow.setContent ('' + '& lt; h3 & Gt; 'Centro .nombre +' '+' '+ centro.lugar +' & lt; / h3 & gt; '+' & lt; p & Gt; Coordian & lt; / p & gt; '+' & lt; p & gt; '+ centro .coordinador.nombre +' '+' & lt; p & gt; '+ Centro.coordinador.email + '& lt; / p & gt;' + '& lt; p & gt; Accountability & lt; / p & gt;' + '& lt; p & gt;' + 'Centrue. Restrictive Nombre + '& lt; / p & gt;' + '
' + centro.responsable.email + '' + '& lt; / div & gt; '); $ Project MapInfoWindow.open ($ project.gmap, Marker);}); $ Project.mapBounds.extend (latlon); It seems to work fine, but if I have 5 markers, then no matter what I click on, infowindow always matches the previous item (position and content),
Any idea what I am missing? I thought the adlist would have to go through the marker
. ..
Google.maps.event.addListener has a problem with the third argument. In that anonymous function the variable is included with the original parent, which will be considered as always assigned final when evaluated with the marker click. Close for more details however you can get the following desired behavior by using the JavaScript Function prototype:
// Loop inside google.maps.event.addListener (marker, 'on Click ', hmmmmarkclick.bind (undefined, marker, i)); // Other code if any ...
defining handleClick
Function handle MarkerClick (marker, index) {if (infobindo typeof infowindow == = 'Undefined') {Infowindow = new google.maps.InfoWindow ({}); } Var data = infoCentros [index] // Useful data // Create dynamic content data with infowindow.setContent ("dynamic content"); Infowindow.open (marker.getMap), marker); // Modify as per your requirement
Comments
Post a Comment