views:

16

answers:

2

Ok, simple question but is it possible to call an external javascript function within a google maps listener?

GEvent.addListener(map,"click", function(overlay, latlng) {
 testfunction(latlng);
});

testfunction doesn't run, so is there a particular way i need to go about this? I'm new to google maps and javascript.

A: 

Of course it is possible. Otherwise it would be useless. Try to include your funnction definition within the same script tag and check if it works.

Vafello
all functions are in same script tag
Queueball
I know the listener is working, because if i do an alert it pops up fine, but calling a function I have defined it doesn't do anything, even if that functions only job is to do an alert.
Queueball
A: 

Try your listener handler function with one parameter at first: a GLatLng object that corresponds to the latitude/longitude where the user clicked on the map.

Give this a try initially:

GEvent.addListener(map, "click", function(latlng) {
    testfunction(latlng);
});

If that doesn't work, ensure that your testfunction is handling the GLatLng type properly (using the object's properties correctly, etc.).

Tim S. Van Haren