I'm using google maps api v3. I need to catch all idle
events on map but I don't want to see them when I change bounds or zoom via code. My problem exists when I use fitBounds
method. I'm using a flag to decide whether an event created because of me or the user. When I used fitBounds, if the bounds are changed, it's fired but sometimes the bounds aren't changed and the event is not fired, so the flag works wrong. It causes the script to ignore user's next event. Here is my code:
var flag = false;
google.maps.event.addListener(map, 'idle', function() {
if(flag) {
// ignore this event
} else {
// do some work
}
flag = false;
});
function fitBounds() {
var bounds = new google.maps.LatLngBounds();
for(var i=0; i<markers.length; i++) {
var location = markers[i].getPosition();
bounds.extend(location);
}
// I need something like whether bounds will change or not after fitBounds?
flag = true;
map.fitBounds(bounds);
}