-1

I am trying to add separate info windows to multiple map markers in a mobile phone app with not much success. When I run my app and click any of the markers the same marker opens its infoWindow every time. Don't know where I have gone wrong.

            result.users.forEach(function(entry){
                latLng = new google.maps.LatLng(entry.user_lat, entry.user_lon);
                marker.push(new google.maps.Marker({map: map, position: latLng}));
                circle.push(new google.maps.Circle({map: map, radius: entry.user_accuracy, strokeWeight:1, strokeOpacity:0.5, fillOpacity:0.2, fillColor: '#AA0000'}));
                circle[circle.length-1].bindTo('center', marker[marker.length-1], 'position');
                info.push(new google.maps.InfoWindow({content: '<b>Phone ID:</b> ' + entry.user_uuid + '<br /><b>Callsign:</b> ' + entry.user_callsign + '<br /><b>Time:</b> ' + entry.user_datestamp}));
                google.maps.event.addListener(marker[marker.length-1], 'click', function() {info[info.length-1].open(map, marker[marker.length-1]);});
                if (entry.user_uuid == device.uuid){
                    map.setCenter(latLng);
                }
            });
Stephen Brown
  • 564
  • 1
  • 9
  • 23
  • possible duplicate of [Google Maps JS API v3 - Simple Multiple Marker Example](http://stackoverflow.com/questions/3059044/google-maps-js-api-v3-simple-multiple-marker-example) – geocodezip Aug 22 '13 at 00:08
  • possible duplicate of [Google Maps API v3 adding an InfoWindow to each marker](http://stackoverflow.com/questions/3158598/google-maps-api-v3-adding-an-infowindow-to-each-marker) – Jonathan Aug 22 '13 at 01:35

1 Answers1

0

The content of your infoWindows must be updated when you open it, else the last content is displayed.

Just modify your addListener :

google.maps.event.addListener(marker, 'click', function () {
    info.setOptions({
        content: MarkerContent
    });
    info.open(map, marker);
}); 
AlexB
  • 7,302
  • 12
  • 56
  • 74