简体   繁体   English

触发任何Google Map事件后如何触发动作

[英]How to fire action when ANY Google Map Event Has Been Fired

I am implementing an app using Google Maps API 3. I would like to know what is the best implementation in dealing with this problem. 我正在使用Google Maps API 3实现一个应用。我想知道什么是解决此问题的最佳方法。 I want to execute an action once ANY event in Google Map has been fired. 我想在Google Map中的ANY事件触发后执行一项操作。 Currently, what I am doing is that I call the function every time a specific event is called. 当前,我正在做的是每次调用特定事件时都调用该函数。 I find this redundant and I have to make a listener for all of the events. 我发现这是多余的,我必须为所有事件做一个监听器。 So, is there a way to generalize this where I can do the following: 因此,有一种方法可以对此进行概括:

google.maps.addListener(everything_on_the_map_canvas, 'ANY_EVENT', function(event) {
  foo();
})

function foo(){
 //do something here
}

Thank you. 谢谢。

If the user decides to continue with map operations, they will have to move the mouse over the map to do anything. 如果用户决定继续进行地图操作,则必须将鼠标移到地图上才能执行任何操作。 So you could simply trap a mousemove . 这样您就可以简单地捕获mousemove

google.maps.event.addListener(map, 'mousemove', function(event) {foo();})

If the user can manipulate the map without moving the mouse over the map, then you will need to listen to other events. 如果用户可以在不将鼠标移到地图上的情况下操纵地图,那么您将需要收听其他事件。

  • bounds_changed will cover most eventualities with zoom and pan, heading and the like bounds_changed将通过缩放和平移,航向等方式涵盖大多数可能发生的情况
  • maptype_id_changed

But that's only three instead of all of them. 但这只是三个,而不是全部。 If the bounds don't change when the tilt does (and you can change tilt from outside the map) you may need to listen for tilt_changed as well. 如果倾斜度发生变化时边界没有变化(并且您可以从地图外部更改倾斜度),则可能还需要侦听tilt_changed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM