Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps API v3 multiple markers Infowindow
    primarykey
    data
    text
    <p>I've used the code below to display a map with multiple markers and infowindows. Now I have encountered the very common problem of the last infowindow showing up on all markers. I've tried all sorts of solutions including: <a href="http://you.arenot.me/2010/06/29/google-maps-api-v3-0-multiple-markers-multiple-infowindows/" rel="nofollow">http://you.arenot.me/2010/06/29/google-maps-api-v3-0-multiple-markers-multiple-infowindows/</a> and this one <a href="http://www.robertbolton.com/blog/google-maps-v3-multiple-markers-and-infowindows-in-a-loop" rel="nofollow">http://www.robertbolton.com/blog/google-maps-v3-multiple-markers-and-infowindows-in-a-loop</a> but none of them fix the problem.</p> <p>Here is my code:</p> <pre><code>var infowindow = null; var geocoder; var map; $(document).ready(function() { initialize(); }); function initialize() { var myOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, scrollwheel: false }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); setMarkers(map, people); infowindow = new google.maps.InfoWindow({ content: "loading..." }); } var people = [ {"userid":"47","lastname":"lastname1","firstname":"firstname1","address":"Paris, France","phone1":"00000000000","phone2":"","email":"me@me.com"}, {"userid":"42","lastname":"lastname2","firstname":"firstname2","address":"Versaille, France","phone1":"0","phone2":"0","email":"me@me.com"} ]; function setMarkers(map, people) { for (var i = 0; i &lt; people.length; i++) { var p = people[i]; geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': p["address"] }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ position: results[0].geometry.location, map: map, html: p["address"] }); var contentString = "Some content"; google.maps.event.addListener(marker, "click", function () { infowindow.setContent(this.html); infowindow.open(map, this); }); } else { alert("Geocode was not successful for the following reason: " + status); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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