Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Api V3: click event firing twice

I am following the MVCObject binding example from this page:

http://code.google.com/apis/maps/articles/mvcfun.html

I want to change the color of the circle and toggle the visibility of the markers when the user clicks on the circle, so I add the listener into the RadiusWidget constructor as follows:

function RadiusWidget() {
    var circle = new google.maps.Circle({
      strokeWeight: 2
    });

    this.set('distance', 50);
    this.bindTo('bounds', circle); 
    circle.bindTo('center', this);
    circle.bindTo('map', this);
    circle.bindTo('radius', this);
    this.addSizer_();

    google.maps.event.addListener(circle, 'click', function()
    {
       alert('circle clicked'); 
    });
  }

My problem is that the click event is firing TWICE. Does anyone know why?

like image 987
lowzhien Avatar asked Oct 18 '25 23:10

lowzhien


1 Answers

I had a similar problem. Could it be a bug in maps API v3? I do not have an answer but a workaround:

google.maps.event.addListener(circle, 'click', function(event) {       
    if (event.alreadyCalled_) {
        alert('circle clicked again'); 
    }
    else {
        alert('circle clicked first time');      
        event.alreadyCalled_ = true;
    }
}); 

The click is still triggered twice but you can detect it.

like image 180
Jiri Kriz Avatar answered Oct 21 '25 15:10

Jiri Kriz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!