I want to trigger a marker drag event on another event, such as a click event on a map. How can i do this?
google.maps.event.addListener (map, 'click', function (pt) { posSelectMarker.setPosition (pt.latLng); // Here I want to fire dragend event. });
Use event.trigger;
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 an object with an event parameter
:
google.maps.event.addListener
google.maps.event.trigger
google.maps.event.addListener(marker_var_name, 'dragend', function(){ alert('drag ended') });
-, addListener , dragend.
addListener
dragend
var marker = new google.maps.Marker({ ... )}; marker.addListener('dragend', function() { // do something });
Source: https://habr.com/ru/post/1751865/More articles:Nokia Application Distribution - distributionПечать диапазона гиперссылок - vbaTracking Changes in Submodules - gitTemplate / Strategy for creating BO from DTO - designJust graduated from the basics of reverse engineering. How to move forward? - assemblyIs there a tool for TFS that quickly scans the author of a single line code? - visual-studio-2010How can I programmatically control the start and stop of Selenium RC - seleniumWhat fonts support a large number of weights? / How to fake a font-weight? - designWhat is the difference in different ways of defining a script? - javascriptFind the longest path between any two nodes - javaAll Articles