Morteza Milani
Morteza Milani

Reputation: 1187

How to fire dragend event of a marker in google maps v3?

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.
});

Upvotes: 5

Views: 15751

Answers (4)

Syakur Rahman
Syakur Rahman

Reputation: 2102

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
});

Upvotes: 1

rynop
rynop

Reputation: 53709

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

Upvotes: 9

Nathan A Haskins
Nathan A Haskins

Reputation: 21

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')
});

Upvotes: 1

TheDeadMedic
TheDeadMedic

Reputation: 9997

Use event.trigger;

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

Upvotes: 9

Related Questions