Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
});
like image 554
Morteza Milani Avatar asked Jun 26 '10 08:06

Morteza Milani


People also ask

How do I add an event to Google Maps?

To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.

How do I change the color of a marker in Google Maps API?

Add different color markerspng at the end of the URL to get a blue marker. To add a green marker simply change it to green-dot. png so that the URL will be http://maps.google.com/mapfiles/ms/icons/green-dot.png .

How do you drag a marker on Google Maps?

You can allow users to move a marker on the map by setting the marker's draggable property to true . For more information about draggable markers, see below.

How do you refresh a marker on Google Maps?

To reload the markers, when you create then, push them to an array. Then create a function where you iterate through the array, setting the markers map as null. After this, erase the array.


2 Answers

Use event.trigger;

google.maps.event.trigger(markerObject, 'dragend', args);
like image 169
TheDeadMedic Avatar answered Nov 15 '22 10:11

TheDeadMedic


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

like image 20
rynop Avatar answered Nov 15 '22 09:11

rynop