I want to listen 'bounds_changed' event when the user moves the map, changes the zoom but I don't want it to be fired when my program calls setCenter or setZoom methods. So I tried removing event before setting center and adding it after, again. However, it didn't worked, My event is still being fired.
var currentBoundsListener = null;
function addBoundsChangedListener() {
currentBoundsListener = google.maps.event.addListener(map, 'bounds_changed', function () {
// Whatever.
});
}
function setCenter(lat, lng) {
google.maps.event.removeListener(currentBoundsListener);
var geo = new google.maps.LatLng(lat, lng);
map.setCenter(geo);
addBoundsChangedListener();
}
I think the map is creating bounds_changed event after I add the new listener to it, like the event is asynchronised.