views:

135

answers:

1

Hello,

my Question is as follows: What does GEvent.addListener(map, "click" function(){...}) return into the callback function? I don't find any information in the GMaps reference at all, can you show me some? The only thing I found out was that there are two parameters, "overlay" and "latLng" that are passed. The name of these parameters should not be of interest right? I could also name them "foo" and "bar" as far as I know. But the parameter "overlay" seems to be empty anyway?

Also I have problems passing these two parameters directly into a callback function I created myself which looks like that...

    GEvent.addListener(gmap, "click", generateMarker(overlay, latLng));

... instead of writing the following, which actually works fine.

    GEvent.addListener(gmap, "click", function(overlay, latLng) {
        generateMarker(overlay, latLng);
    });
+2  A: 

Your first example is trying to pass the result of calling generateMarker(overlay, latLng) to addListener which of course isn't going to work. The second example is the correct way to do it.

You can name the parameters passed to your callback anything you like.

Overlays are objects on the map that are tied to latitude/longitude coordinates, so I'm guessing overlay is whatever object was clicked on. However, it looks like version 3 of the API passes an event object to the callback:

google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng);
});

If there is nothing in the documentation about this, you can always inspect event using Firebug.

Alex - Aotea Studios