javascript - Google Maps API infowindows all have the same content -
i have old infowindows in loop problem content last loop showing in infowindows. yes know there several questions on stack overflow none of them seem work me.
this javascript:
var map; var geocoder; $(function () { var mapoptions = { zoom: startzoom, center: new google.maps.latlng(startlat, startlng) } var marker, i; $('#map-canvas').height($('#map-canvas').width() / 2); var mapoptions = { zoom: startzoom, center: new google.maps.latlng(startlat, startlng) } map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); if ( ! isaddress && $('#country').val() > 0) { geocoder = new google.maps.geocoder(); geocoder.geocode({'address': $('#country').find('option:selected').text()}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); map.fitbounds(results[0].geometry.viewport); } }); } (i = 0; < distributors.length; i++) { var $distributor = distributors[i]; var marker = new google.maps.marker({ position: new google.maps.latlng($distributor.latitude, $distributor.longitude), map: map }); var infowindow = new google.maps.infowindow(); var html = '<div class="container-fluid" style="width: 300px">\ <h1 class="row-fluid">\ '+($distributor.logo ? '<div class="span3"><img src="'+$distributor.logo+'" style="width: 100%"></div>' : '')+'\ <span class="span9">'+$distributor.name+'</span>\ </h1>\ <div class="row-fluid">\ <div class="span6">'+$distributor.address+'<br>'+$distributor.postcode+'</div>\ <div class="span6">'+($distributor.url ? '<a href="'+$distributor.url+'">'+$distributor.url+'</a>' : '')+'<br>'+$distributor.contactnumber+'</div>\ </div>\ </div>'; google.maps.event.addlistener(marker, 'click', (function(marker, i) { return function() { infowindow.setcontent(html); infowindow.open(map, marker); } })(marker, i)); } })
so far i've tried this answer, variables mentioned don't match have , couldn't make them match up, didn't work.
i've tried this answer, instead of getting different content removed 1 of markers.
what doing wrong? can please me sort out?
try after creating infowindow , html objects:
marker.html = html;
then build event listener this:
google.maps.event.addlistener(marker, 'click', function () { infowindow.setcontent(this.html); infowindow.open(map, this); });
Comments
Post a Comment