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

  • SEARCH
  • Home
  • 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 8383695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:13:25+00:00 2026-06-09T17:13:25+00:00

I have a Google Maps implementation which uses the Google Maps Utility Library v3

  • 0

I have a Google Maps implementation which uses the Google Maps Utility Library v3 (http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html) for clustering markers. It works perfectly.

Now though, I want to add infowindows to the markers. The cluster markers work fine as they are, so I want to keep the behaviour on those (i.e. they zoom in when you click them) but when a normal single marker is clicked I want to display an infowindow.

The complete code is as follows:

var _iconCenter = new google.maps.MarkerImage('/css/img/map-marker.png',
  new google.maps.Size(38, 48),
  new google.maps.Point(0,0),
  new google.maps.Point(19, 44));

var shadow = new google.maps.MarkerImage('/css/img/map-marker-shadow.png',
  new google.maps.Size(57, 49),
  new google.maps.Point(0,0),
  new google.maps.Point(7, 44));

var _icon = '/css/img/map-marker-purple.png';
var infowindow;
var markersArray = [];
var map;
var currentPosition = 0;
var currentmarker;
var firstload = true;
var maploaded = false;
var interval = 5000;
var geocoder;

var stylez = [];


function initialize(items,loop,zoom) {
  geocoder = new google.maps.Geocoder();
  if (items.length > 0) {
    var latlng = new google.maps.LatLng(items[0].Lat, items[0].Lng);
    var myOptions = {
      zoom: zoom,
      center: latlng,
      //mapTypeControl: false,
      streetViewControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map"), myOptions);
    map.setOptions({styles: stylez});

    for (var i = 0; i < items.length; i++) {
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(items[i].Lat, items[i].Lng),
        title: items[i].Title,
        icon: _icon,
        shadow: shadow,
        infocontent: items[i].Description
      });
      marker.setMap(map);
      markersArray.push(marker);
    }


    //set style options for marker clusters (these are the default styles)
    mcOptions = {
      gridSize: 44
    }

    var markerCluster = new MarkerClusterer(map, markersArray, mcOptions);
    google.maps.event.addListener(map, "tilesloaded", function () {
      if(loop == true){
        SetLoop();
      }
    });

    google.maps.event.addListener(marker, "click", function () {
      alert('test');
      //infowindow.setContent('test');
      //infowindow.open(map,this);
    });

  }
}


function SetLoop() {
//This will fire everytime map loads or recenteres
  maploaded = true;
  if (firstload) {
    firstload = false;
    Recenter();
  }
}

function Recenter() {
  //If previous iteration is not loaded completely, wait to avoid errors
  //It could happen for slow internet connection
  if (maploaded) {
    maploaded = false;
  } else {
    //keep adding 1 second to interval for slow connection till page loads
    interval = interval + 1;
    setTimeout("Recenter()", interval);
    return;
  }

  if (infowindow != null && currentmarker != null) {
    //currentmarker.icon = _icon;
    currentmarker.icon = _iconCenter;
    currentmarker.setMap(map);
    infowindow.close(map, currentmarker);
  }

  markersArray[currentPosition].icon = _iconCenter;
  markersArray[currentPosition].setMap(map);
  map.setCenter(new google.maps.LatLng(markersArray[currentPosition].getPosition().lat(), markersArray[currentPosition].getPosition().lng()));

  infowindow = new google.maps.InfoWindow({
    content: markersArray[currentPosition].infocontent,
    size: new google.maps.Size(50, 50)
  });
  infowindow.open(map, markersArray[currentPosition]);
  currentmarker = markersArray[currentPosition];
  if (currentPosition >= markersArray.length - 1) {
    currentPosition = 0;
  } else {
    currentPosition++;
  }
  if (markersArray.length > 1) {
    setTimeout("Recenter()", interval);
  }
}

As you can see, for demonstration purposes only, I’m calling a crude alert event on the marker click listener, but it’s not firing at all. Just nothing happens when I click a normal marker and there are no errors in the developer tools console of the browser. I’m wondering if it’s something to do with having another event listening to the map loading, but I’m at the edge of my understanding of this and without any errors I’m struggling to know how to debug it.

Can anyone point me in the right direction to get this working?

Thanks folks!

  • 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-06-09T17:13:26+00:00Added an answer on June 9, 2026 at 5:13 pm

    I think that the problem is that you hand the markers over to the clusterer before adding the event listener. Try adding the listener as soon as the marker has been created, so that when you pass the markersArray to the clusterer the event listteners are already attached.
    So try:

    for (var i = 0; i < items.length; i++) {
          var marker = new google.maps.Marker({
            position: new google.maps.LatLng(items[i].Lat, items[i].Lng),
            title: items[i].Title,
            icon: _icon,
            shadow: shadow,
            infocontent: items[i].Description
          });
          marker.setMap(map);
    
          //attach the listener now, before pushing into the array
          attachListener(marker,'marker:'+i);
          markersArray.push(marker);
        }
    

    and then:

        function attachListener(marker,content){
            google.maps.event.addListener(marker, "click", function () {
    //      alert('test');
            infowindow.setContent(content);
            infowindow.open(map,this);
            });
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a google maps directions link shown in XML: http://maps.googleapis.com/maps/api/directions/xml?origin=111%20Davisville%20Avenue,Toronto,ON&destination=469%20King%20Street%20West,%20Toronto,%20ON&sensor=false&dirflg=r Even though it
I'm building an web app that uses this code to search for addresses: http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/places-autocomplete.html
I have routes as Google Maps Polylines in my project (an example, http://rutasgdl.com/rutas/626-2 )
I have a google maps api v3, which uses The Di Lab's plugin for
In my google maps program I have simple KML parser which retrieve only coordinates
I have a google maps app which plots markers as it loads. One of
I have a Google Maps KML feed which stopped working a few days ago.
I am making an android app in which I have used google maps. these
I already made a simple android application, which I also have integrated Google Maps
I'm looking for some help with a Google Maps implementation. I have to code

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.