Rom
Rom

Reputation: 133

Trying to add a click listener to GO Maps Marker in WP GO MAPS Pro plugins

I'm using WP Go Maps Pro plugin. I'm trying to add a click event listener to a google map marker. I get all the markers infos, but for some reason it won't add the listener. Any idea what I'm doing wrong ?

jQuery(($) => {
  $(document.body).on('markersplaced.wpgmza', () => {////whait for the markers to be ready
    var map = WPGMZA.maps[0];////Get the map
    if(map.markers && map.markers.length > 0) {////Get the markers
      map.markers.forEach(function(marker) {////for each markers
        console.log(marker);// it's logging each marker, I get all the infos about it.
        google.maps.event.addListener(marker, 'click', function() {// but addListener is not working
          console.log('Marker clicked:', marker.title); 
        });
      });
    }
  });
});

Upvotes: 1

Views: 78

Answers (1)

Rom
Rom

Reputation: 133

thanks for the help, I found the answer ! It's :

marker.addEventListener('click', function() {
   console.log('click');                     
});

Upvotes: 1

Related Questions