Google Maps Markers disappear after multiple fitBounds() calls

Problem Description

  • You have mulitple fitBounds() calls to display your Google Map
  • After some calls  your draggable Markers disappear from your Map
  • If you slightly move the Map the Markers get displayed again
  • Very likely you hit Googe Maps Bug 5176

Workaround 1

  • Create your Maps Marker with draggable set to false
var tMarker = new google.maps.Marker({
    position: markerPos,
    draggable: false, 

Workaround 2

  • In case your need a draggable marker call map.panBy(0,0) to fix the problem
  • Flow
    • fitBounds() triggers the center_changed event
    • Within this event call panBy() without moving the map at all
google.maps.event.addListenerOnce(gMap, 'center_changed', function() {
    var gMap = myControlPanel.getMap();  // Die and give up if gMap is null
    gMap.panBy(0,0);
});

gMap.fitBounds(bounds);

Leave a Reply

Your email address will not be published. Required fields are marked *