How to listen for user generated zoom in Google Maps?

前端 未结 5 2120
借酒劲吻你
借酒劲吻你 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:55

    I wouldn't just hook in to the +/- buttons (or buttons on your own custom control for that matter). The user can change the zoom on the map with the mouse wheel, or by double-clicking on the map. Plus, you'd be relying on implementation detail rather than documented API, which is a major no-no.

    This really means the only reliable, documented way to detect a change in zoom is to listen to the zoom_changed event of the Map.

    If your event handler can't determine whether the event came from user action or an API call, there's two approaches:

    • Set a flag before calling an API function so that you know you can ignore this change.
    • Can you re-architect your app such that it does not matter whether a zoom change came from code or the user?

提交回复
热议问题