Skip to content Skip to sidebar Skip to footer

What Does "google.maps.event.adddomlistener(window, 'load', Initialize);" Mean?

What does this mean? google.maps.event.addDomListener(window, 'load', initialize); I have the function 'initialize()' but I also added two paramters, longitude and latitude so it'

Solution 1:

The google.maps.event.addDomListener adds a DOM event listener, in this case to the window object, for the 'load' event, and specifies a function to run.

from the documentation:

addDomListener(instance:Object, eventName:string, handler:function(?), capture?:boolean)Return Value: MapsEventListenerCross browser event handler registration. This listener is removed by calling removeListener(handle) for the handle that is returned by this function.

The initialize in google.maps.event.addDomListener(window, 'load', initialize); is a function pointer, you can't pass arguments with that. To pass in arguments, wrap it in an anonymous function (that doesn't take arguments):

google.maps.event.addDomListener(window, 'load', function () {
   initialize(latitude, longitude);
});

Solution 2:

It looks like it calls initialize when the DOM is loaded, but probably without the parameters, if I interpret the docs correctly.

But you could wrap the call inside another function and pass that to the method. It can be an anonymous function, like so:

google.maps.event.addDomListener(window, 'load', function(){
  initialize(50.0000, 60.0000);
});

Post a Comment for "What Does "google.maps.event.adddomlistener(window, 'load', Initialize);" Mean?"