Note that there are some explanatory texts on larger screens.

plurals
  1. POgoogle maps multi marker info window not working
    text
    copied!<p>I'm using Google Maps API on my web page. I'm try to add multiple markers to the page with info windows. The markers get added ok, but the info windows all have the info for the last marker. any ideas?</p> <pre><code> &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;Services&gt; &lt;asp:ServiceReference Path="http://testserver/se1/WebServices/ShelterWebService.asmx" /&gt; &lt;/Services&gt; &lt;/asp:ScriptManager&gt; &lt;asp:LinkButton ID="BtnHome" runat="server" onclick="BtnHome_Click"&gt;Home&lt;/asp:LinkButton&gt; &lt;div id="map_canvas"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; var geocoder; var map; var addresses; function GetShelters() { ShelterExpress.WebServices.ShelterWebService.GetShelters('', OnGetSheltersComplete); } function OnGetSheltersComplete(retValue) { addresses = new Array(); for (x in retValue) { addresses.push(retValue[x]["Address"]); } GenerateMap(); } function GenerateMap() { /* Create the geocoder */ geocoder = new google.maps.Geocoder(); /* Some initial data for the map */ mapOptions = { zoom: 10 , center: new google.maps.LatLng(0, 0) , mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); //var infowindow = new google.maps.InfoWindow(); var marker, i; if (geocoder) { for (var item in addresses){ geocoder.geocode({ 'address': addresses[item] }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { /* Position the map */ map.panTo(results[0].geometry.location); /* Put a marker */ marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, title: addresses[item] }); var infowindow = new google.maps.InfoWindow({ content: addresses[item] }); infowindow.open(map, marker); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); } }); } } } $(document).ready(function() { GetShelters(); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload