1

I have Google Maps with Javascript API with a single marker on it. This single marker has an infowindow showing.

When I call marker.setPosition() to move the marker, if the infowindow is open, and the marker is off-screen, then the map pans to bring the marker and infowindow into view.

How can I stop this behavior? I want to move the marker, but leave it off screen, and leave the map position where it is.

If I close the infowindow, then calling marker.setPosition() doesn't pan the map. The unwanted behavior only happens when the infowindow is open.

Matt
  • 1,412
  • 3
  • 15
  • 18
  • possible duplicate of [Prevent map from repositioning when clicking a marker (Google Map v3)](https://stackoverflow.com/questions/14596635/prevent-map-from-repositioning-when-clicking-a-marker-google-map-v3) – geocodezip Aug 24 '19 at 17:05
  • possible duplicate of [Preventing Google Maps Move After Displaying Infowindow](https://stackoverflow.com/questions/18404948/preventing-google-maps-move-after-displaying-infowindow) – geocodezip Aug 24 '19 at 17:08
  • possible duplicate of [Google Maps: How to prevent InfoWindow from shifting the map](https://stackoverflow.com/questions/2488999/google-maps-how-to-prevent-infowindow-from-shifting-the-map) – geocodezip Aug 24 '19 at 17:09

1 Answers1

3

By default, info windows will pan the map so that they are fully visible when they're open. You could set disableAutoPan to true on the InfoWindowOptions that are set on google.maps.InfoWindow when created. For example, where you declare your info window:

let infowindow = new google.maps.InfoWindow({
      content: "Blah Blah Blah",
      // other code ...
      disableAutoPan: true
});

API Reference: https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindowOptions.disableAutoPan

JoshG
  • 6,472
  • 2
  • 38
  • 61