Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "google.maps.event.addDomListener(window, 'load', initialize);" mean? [duplicate]

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's like this:

function initialize(longitude, latitude){

}

because of this do I have to do anything to the 'initialize' in the line:

google.maps.event.addDomListener(window, 'load', initialize);
like image 762
Feath Avatar asked Sep 27 '22 13:09

Feath


2 Answers

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: MapsEventListener
Cross 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);
});
like image 139
geocodezip Avatar answered Oct 07 '22 21:10

geocodezip


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);
});
like image 45
GolezTrol Avatar answered Oct 07 '22 19:10

GolezTrol