1

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); 
        });
      });
    }
  });
});
2
  • 2
    Are you getting any errors in the console? Commented Aug 5, 2024 at 20:20
  • try like this: 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.on('click',markers,function(){ console.log('Marker clicked:', $(this).attr('title')); }); } }); }); Commented Aug 6, 2024 at 8:40

1 Answer 1

1

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

marker.addEventListener('click', function() {
   console.log('click');                     
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.