0

I have a google map which gets refreshed for marker data on the bounds_changed event. On click of the marker i have a info window open up. Now if a marker is at the corner of the map it moves a map a bit to fit the pop up into the map view.

Now at this time my bounds_changed event gets fired again and it will bind all the markers again with new data. So that's not a very smooth UX. How can i resolve this ?

Thanks in advance.

Akshat G
  • 214
  • 2
  • 14

1 Answers1

2

Theoretical solution: You will need to do NOTHING when bounds_changed event fired.

Practical solution:

1) You will have to addlistener to bounds_changed event and ignore the event. The way you do that is:

var ignore = false; // this var is global;
currentBoundsListener = google.maps.event.addListener(map, 'bounds_changed', function () {
if(ignore) {
   ignore = false;
   return;
}

// Whatever.
});

2) ignore variable is set to false by default and needs to be set to true when the user clicks on the marker, when infowindow is shown.

   google.maps.event.addListener(marker, 'click', (function(marker, i) {
                ignore = true;
                })(marker, i)); //end add marker listener

1) How ignore bounds_changed event 2) How add listener to marker click event

Community
  • 1
  • 1
alsafoo
  • 778
  • 4
  • 18
  • Why it needs to be on bounds_changed? Pls copy all your code that is related to your question – alsafoo Mar 21 '16 at 07:10
  • because data is too large to load on first so as we move the map or zoom out or zoom in and place is changed we need to refresh the list. – Akshat G Mar 21 '16 at 07:16