I have a problem using setTimeout. I have been using it lots of times and it always works the way I expect it to. Even when I put the code in a separate function it works but just in this case it has a weird behaviour.
Here is a the very code:
RoutePatternPoint.prototype.showOnMap = function(map)
{
var that = this;
google.maps.event.addListener(this.marker, "click", function(event)
{
window.setTimeout(function(){
if(RoutePatternPoint.markerDoubleClickFix === false) { doSomething(); }
RoutePatternPoint.markerDoubleClickFix = false;
},350);
});
google.maps.event.addListener(this.marker, "dblclick", function(event)
{
RoutePatternPoint.markerDoubleClickFix = true;
});
}
The problem is that google maps api v3 has a bug when single and double click events are implemented - both of them gets executed.
So the solution is to slow down the single click event and see if a double click event is executed. If the double click event is executed then we interrupt the single click event.
Unfortunately my code is not working the way I want it to so I decided to write some alert function and see what happens. Guess what? The setTimeout function inside the single click event is executed twice.
What am I doing wrong?
RoutePatternPoint.markerDoubleClickFix === falseis not going to be true the first time around, unless you explicitly set that tofalsesomewhere else. Probably better to use!RoutePatternPoint.markerDoubleClickFixor==.showOnMap()was called twice and the listener was added twice.