Search code examples
javascriptgoogle-mapsdraggable

Draggable google map markers


I have been working with google maps and now have a requirement to make a draggable marker that I can place on the map.

Is this a big difference in complexity from just placing markers by geolocation coordinates? What is the best way of going about making draggable markers that users can set?

Thank you, Alex


Solution

  • You dont mention which version of the API you are using, so i will asume v3... There is a draggable property that you can either set in the constructor using the options parameter 'draggable: true' or by invoking the setDraggable(true) function after it is created.

    Check http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker for more info.

    Edit: For version 2 there are enableDragging() and disableDragging() functions...

    As for adding markers, perhaps subscribe to the mouse click event on the map, and then add a marker in there. The coordinates are passed into the event handling function as part of the event parameter.