Google map api v3 "dragend" event fired more than ones

google-maps-api-3

Solution

True, this is rather annoying but.. don't despair just yet - you can fix it with simple JavaScript:

map.dragInProgress = false; //adding flag to already existing map object to keep DOM clean
google.maps.event.addListener(map, 'dragend', function() {
  if(map.dragInProgress == false) { //only first shall pass
    map.dragInProgress = true;
    window.setTimeout(function() {
        console.log('Note how you will see this console message only once.');
        //cast your logic here
        map.dragInProgress = false; //reset the flag for next drag
    }, 1000);
  }
});

In short, this allows you to receive dragend event only once per second. Make sure your script doesn't die in the middle of your logic or that first will be the last drag. You can use try/catch/finally to overcome that. Enjoy!

Problem

Currently I have this listener events on my google maps (api v3): ``` google.maps.event.addListener(Map, 'center_changed', FixedMarkerInCenter); google.maps.event.addListener(Map, 'zoom_changed', FixedMarkerInCenterZoom); google.maps.event.addListener(Map, 'dragend', FindReverseGeocode }); ``` The problem is that the 'dragend' event fired more than ones (at least four times) and the function 'FindReverseGeocode' happen many times. Does anyone know the problem?

Original source