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 7054253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:36:15+00:00 2026-05-28T03:36:15+00:00

I have a click listener for each of my markers calling the function displayInfo

  • 0

I have a click listener for each of my markers calling the function displayInfo, a custom infoBox..

google.maps.event.addListener(markers[i], 'click', function() {
        //stop updating markers
         google.maps.event.removeListener(updateMarkersProcess);

        //call display custom infowindow function
        displayInfo(this);
    });

I’ve got a bounds_change listener on my map for ‘binding’ a custom infobox to a marker. Like so:

function displayInfo(marker) {

 var e = $('infobox');

overlay.getPanes().floatPane.appendChild(e);

displayInfoProcess = google.maps.event.addListener(map, 'bounds_changed', function() {
    
    show('infobox');
    
    var markerOffset = overlay.getProjection().fromLatLngToDivPixel(marker.position);

    e.style.top = markerOffset.y + 20 + 'px';
    e.style.left = markerOffset.x - 40 + 'px';

    e.innerHTML = marker.store + '<br><em>' + convertDistance(marker.distance);   
     
});
map.panTo(marker.position); 
}

I then have a click listener on the map to hide the infoBox and stop the bounds_change listener…

[REMOVE LISTENER CODE HERE]

google.maps.event.addListener(map, 'click', function() {

       google.maps.event.removeListener(displayInfoProcess);
       // google.maps.event.clearListeners(map, 'bounds_changed');
       hide('infobox');
     
    });

This hides the infoBox but the thing is, this doesn’t seem to remove the listener. Here’s a print from the log:

//Before clicking a marker (no listener)

displayInfoProcess
null

//After clicking a marker (a listener)

displayInfoProcess
Ue
b: qh
d: "bounds_changed"
e: function () {
id: 1480
j: null
l: 0
proto: Ue

//After clicking on map (still, a listener)

displayInfoProcess
Ue
b: null
d: "bounds_changed"
e: null
id: 1480
j: null
l: 0
proto: Ue

And to make things really weird, if I..

1) Click a marker This shows infoBox1

2) Click another marker This shows infoBox2 instead of 1

3) Click the map This hides infoBox2

4) Pan the map

..the infoBox(1) from the FIRST marker shows up!

Is there a remedy?

  • 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-28T03:36:16+00:00Added an answer on May 28, 2026 at 3:36 am

    The listener reference is being removed (look at the b: and e: properties, they are both null), all that remains is a shell. If the listener wasn’t being removed anytime you attempt to pan the map it would snap back to the marker that added the listener.

    Since all you seem to be doing with the displayInfoProcess event is showing the infobox I would use the google.maps.event.addListenerOnce() This will remove the listener immediately after it is executed.

    function displayInfo(marker) {    
        google.maps.event.addListenerOnce(map, 'bounds_changed', function() {
            //set infobox info...
        });
        map.panTo(marker.position);
    }
    

    I personally do not like using the click event on the map. When a user is clicking on the map they are usually trying to pan the map so I use the dragstart, drag, and dragend events instead. By using the dragstart event you don’t need to release the mouse button before trying to pan the map.

    Here is an example using addListenerOnce and dragstart : http://jsfiddle.net/bryan_weaver/vPN7R/

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

Sidebar

Related Questions

I have added a click listener to all my Markers in google maps. I
I have a listener like this: $('.delete').click(function() { ...some stuff }); Also, on the
I have written the following function which adds an event listener and registers the
i have public class ExperimentAllInOneActivity extends Activity implements OnClickListener on each button click listener
Possible Duplicate: Looping through Markers with Google Maps API v3 Problem I have a
i have a google map with multiple markers and each has its own infowindow.
I have the same event listener for many markers in my Javascript. How do
I am using Google Maps API v3 , and have several map markers that
I have a button that plays an audio file on its click listener. If
I have a listener for click events from which I need to exclude some

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.