Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript click event for any google maps markers?

I need to make something happen when any google maps marker is clicked on. Im using the demo from this link as a starting point:

http://gmap3.net/examples/tags.html

UPDATE - ive tried the following:

$.each(markers, function(i, marker){
  marker.click(function(){  
     alert('alert');
  });
});

$.each(markers, function(i, marker){
  $(marker).click(function(){  
     alert('alert');
  });
});

UPDATE Ive tried adding this middle section to existing code:

        $.each(markers, function(i, marker){
            marker.setMap( checked ? map : null);

           //added code begins
            $(marker).click(function(){ 
                 alert('dfd');
              });
           //added code ends

        });
like image 279
Evanss Avatar asked Aug 03 '26 04:08

Evanss


1 Answers

google.maps.event.addListener(marker, 'click', function() {

});

ref: https://code.google.com/apis/maps/documentation/javascript/events.html#UIEvents

Example : http://jsfiddle.net/diode/yXQwp/

like image 113
Diode Avatar answered Aug 04 '26 20:08

Diode



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!