Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding class method to event in google maps v3?

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?

like image 777
Eric Palakovich Carr Avatar asked Feb 27 '26 10:02

Eric Palakovich Carr


1 Answers

Oh right. Closures. Duh.

var self = this;
google.maps.event.addListener(this.drag_marker, "dragstart", function(latlng) {
    self.start_dragging_route(latlng);
});
like image 130
Eric Palakovich Carr Avatar answered Mar 02 '26 00:03

Eric Palakovich Carr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!