如何检查Google Maps是否已满载?

I’m embedding Google Maps into my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes.

Is there a way to auto-detect when Google Maps has fully loaded, including tile downloads and all?

A tilesloaded() method exists that is supposed to accomplish exactly this task but it does not work.

猿Tom2020/03/24 16:35:44

其中变量map是GMap2类型的对象:

    GEvent.addListener(map, "tilesloaded", function() {
      console.log("Map is fully loaded");
    });
达蒙2020/03/24 16:35:44

您可以GMap2.isLoaded()n毫秒检查一次该方法,以查看地图及其所有图块是否已加载(window.setTimeout()或者window.setInterval()是您的朋友)。

虽然这不会给您确切的加载完成事件,但足以触发Javascript。

LGil泡芙2020/03/24 16:35:44

如果您使用的是Maps API v3,则此操作已更改。

在版本3中,您实质上想为bounds_changed事件设置一个侦听器,该事件将在加载地图时触发。一旦触发,请删除侦听器,因为您不想在每次视口边界更改时都被告知。

随着V3 API的发展,这种情况将来可能会改变:-)

番长Green2020/03/24 16:35:44

GMap2::tilesloaded() 将是您正在寻找的事件。

有关参考,请参见GMap2.tilesloaded