I’m developing a Google Map API v2 app, where markers are loaded from a database. These markers can then be dragged to a new location by a user and saved to the database.
I’m adding these markers as draggable, however I don’t just want the users to be able to drag them accidentally. So I have added a button to enable the dragging and then press again to disable it.
Only problem is I’m not sure how I can toggle the ability to drag the markers without reloading them again, as there could be a few hundred markers on the map and may take some time.
Any ideas how I could achieve this?
Thanks
That should be very easy to do. First you need to keep a reference to all your markers. Then to toggle the dragging behaviour, you can simply iterate through your markers and call the
enableDragging()or thedisableDragging()method on each marker.For this to work, your markers will have to be initialized with the
GMarkerOptions.draggableoption set totrue, but I assume you are already doing this.Here’s a fully working example: