5
votes

I want to fire dragend event of a marker in another event say click event on the map. how can I do that?

google.maps.event.addListener(map,'click',function(pt){
   posSelectMarker.setPosition(pt.latLng);
   //Here I want to fire dragend event.
});
4

4 Answers

9
votes

Use event.trigger;

google.maps.event.trigger(markerObject, 'dragend', args);
8
votes

This is a bit more complete:

theListener = google.maps.event.addListener(posSelectMarker,'dragend',function(event){
    console.log(event.latLng);
});

Note that you can get at the object with the event param

1
votes

Should be:

google.maps.event.addListener

instead of:

google.maps.event.trigger

Quick example:

google.maps.event.addListener(marker_var_name, 'dragend', function(){
    alert('drag ended')
});
1
votes

If you have the marker object, you could call addListener directly to add a dragend event.

var marker = new google.maps.Marker({
    ...
)};

marker.addListener('dragend', function() {
    // do something
});