views:

40

answers:

1

In V2 of the Google Maps API, you could bind map events to a class method using the GEvent.bind function:

GEvent.bind(this.drag_marker, "dragstart", this, this.start_dragging_route);

In the example above pretend that's a link from a prototype.init function, where start_dragging_route is a method inside the class.

It appears that the bind method doesn't exist anymore, at least not in the documentation. If it's true I have one way to solve it, but it's a touch ugly so I'd love to hear some other solutions to this problem.

How can I implement the GEvent.bind function in Google Maps API V3?

+1  A: 

Oh right. Closures. Duh.

var self = this;
google.maps.event.addListener(this.drag_marker, "dragstart", function(latlng) {
    self.start_dragging_route(latlng);
});
Eric Palakovich Carr