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. });
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. });
Use event.trigger
;
google.maps.event.trigger(markerObject, 'dragend', args);
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
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')
});
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
});
© 2022 - 2024 — McMap. All rights reserved.