Search code examples
javascriptmarkerjquery-gmap3

how can i add click functionality to gmap3 function?


I am using gmap 3 for plotting map. i need to enable on click functionality on marker. am using the following code

var contact = {"lat":"26.207293", "lon":"50.583730"}; //Change a map coordinate here!
  try {
    var mapContainer = $('.map');
    mapContainer.gmap3({
      action: 'addMarker',
      marker:{
        options:{
          icon : new google.maps.MarkerImage('img/assets/marker.png')
        }
      },
      latLng: [contact.lat, contact.lon],
      map:{
        center: [contact.lat, contact.lon],
        zoom: 14
        },
      },
      {action: 'setOptions', args:[{scrollwheel:false}]}
    );
  } catch(err) {

  }

i tried this too.eventes function.still not woring.

events:{
              click:function(){
                alert("I'm the last one, and i have my own click event");
              }

Solution

  • I have tried your code, and changed a few things. This works:

    var contact = {"lat":"26.207293", "lon":"50.583730"}; //Change a map coordinate here!
    $("#my_map").gmap3({
      marker:{
        values: [[contact.lat, contact.lon]],
        options: {
          draggable: false
        },
        events:{
          click: function() {
            alert('bla');
          }
        }
      },
      map: {
        options: {
          center: [contact.lat, contact.lon],
          zoom: 14
        }
      }
    });
    

    Demo: http://jsfiddle.net/aJuBZ/