S
S
Sergey2018-10-01 15:44:44
JavaScript
Sergey, 2018-10-01 15:44:44

How to remove an event handler in Google Maps?

Removing event handlers in Google Maps is described here . How to apply this information in my case? Can't figure out how to do this if a loop is applied.

document.getElementById('myCheckbox').addEventListener('change', function() {
  if (this.checked) {
    for (var i = 0; i < markers.length; i++) {
      var listener = google.maps.event.addListener(markers[i], 'dblclick', function() {
        map.setZoom(17);
        map.panTo(this.getPosition());
      });
    }
  } else {
    // Тут должно произойти удаление обработчиков, что-то типа
    // google.maps.event.removeListener(listener);
  }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-10-01
@SergeiB

for (var i = 0; i < markers.length; i++) {
      google.maps.event.clearListeners(markers[i], 'dblclick');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question