Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:49:40+00:00 2026-05-27T05:49:40+00:00

I am using the MarkerCluster library for Google Maps v3 and am having a

  • 0

I am using the MarkerCluster library for Google Maps v3 and am having a problem getting the info windows to work properly for the markers.

What’s happening is that the markers are being placed in the correct location, however when you click on them the info window for the last marker created pops up no matter which marker is clicked on.

Here is the JavaScript:

<script type="text/javascript">
  function initialize() {
    var center = new google.maps.LatLng(37.4419, -122.1419);

      var myOptions = {
        zoom: 3,
        center: new google.maps.LatLng(46.90, -121.00),
        mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      map = new google.maps.Map(document.getElementById("map"), myOptions);

    var infowindow = new google.maps.InfoWindow({ 
        //size: new google.maps.Size(150,150)
        maxWidth: 500,
    });

    var markers = [];

    for (var i = 0; i < businesses.length; i++) {

        var latLng = new google.maps.LatLng(businesses[i].latitude, businesses[i].longitude);

        var contentString = businesses[i].latitude;

        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            zIndex: Math.round(latLng.lat()*-100000)<<5
        });

        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(contentString); 
            infowindow.open(map,marker);
        });

        markers.push(marker);


    }

    var markerCluster = new MarkerClusterer(map, markers);

  }

  google.maps.event.addDomListener(window, 'load', initialize);
</script>

I’m sure it’s something simple that I keep overlooking, but I haven’t been able to pin point the problem.

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:49:40+00:00Added an answer on May 27, 2026 at 5:49 am

    I had similar problems which I fixed by using a closure when adding the event listener:

    for (var i = 0; i < businesses.length; i++) {
    
        var latLng = new google.maps.LatLng(businesses[i].latitude, businesses[i].longitude);
    
        var contentString = businesses[i].latitude.toString();
    
        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            zIndex: Math.round(latLng.lat()*-100000)<<5
        });
    
        google.maps.event.addListener(marker, 'click', (function(marker, contentString) {
          return function() {
            infowindow.setContent(contentString); 
            infowindow.open(map,marker);
          };
        })(marker, contentString));      
    
        markers.push(marker);
    }
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling trying to cluster 50 markers using the markerclusterer v3 with Google maps
I'm using GMaps V3 with MarkerClusterer from http://code.google.com/p/gmaps-utility-library-dev/ Markers displayed on the map are
I am using the MarkerCluster.js to create clustering in my google maps api. The
This is driving me mental. I'm using MarkerCluster with google maps v3, and it
I'm working on an application that generates a large number of Google Map markers
Hi everyone, I'm making a google map with markers of our company's customers,so that
I am currently using markercluster plugin with jquery ui maps. I have two arrays
I have a bit of a puzzle on my hands. I'm Using Google Maps
I have a Google map that is showing a number of markers. When the
I am currently developing a kind of google maps overview widget that displays locations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.