How to listen for user generated zoom in Google Maps?

前端 未结 5 2106
借酒劲吻你
借酒劲吻你 2021-02-04 06:24

I want to know when a Google Maps zoom_changed event is fired specifically by a user interaction with the +/- zoom buttons. If I use a general event listener for zoom_changed,

5条回答
  •  [愿得一人]
    2021-02-04 06:49

    var zoomFlag = "user"; // always assume it's user unless otherwise
    
    // some method changing the zoom through API
    zoomFlag = "api";
    map.setZoom(map.getZoom() - 1);
    zoomFlag = "user";
    
    // google maps event handler
    zoom_changed: function() {
      if (zoomFlag === "user") {
        // user zoom
      }
    }
    

提交回复
热议问题