How to make the infowindow appear depending upon t

2019-08-18 02:41发布

问题:

I am displaying few locations in google maps. I refresh these locations if a user zoom in/out or drags the map. Now the issue is if i click on the marker of a location then the info window opens up and drags the map if it doesn't have any space to show. This dragging causes my locations to be refreshed and hence my marker vanishes.

I tried disableAutoPan: true but then the info window is not seen only. Is there any way that the info window auto adjust itself. is there any way to sort this out?

回答1:

Use a global variable to indicate when the refresh should be ignored, for example:

// Global var
var ignoreRefresh = false;

google.maps.addListener(marker,'click', function(){
  ignoreRefresh = true;
  infoWindow.setContent('Hello');
  infoWindow.open(map,marker);
})

function refresh(){
  if (ignoreRefresh) {
    ignoreRefresh = false;
    return;
  }
  //...
  //do your normal refresh of data
  //...

}