/ Published in: JavaScript
Add draggable markers on a Google map with a click, remove marker on click
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
google.maps.event.addListener(map, 'click', addPoint); function addPoint(event) { var marker = new google.maps.Marker({ position: event.latLng, map: map, draggable: true }); markers.push(marker); google.maps.event.addListener(marker, 'click', function() { marker.setMap(null); for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i); markers.splice(i, 1); }); google.maps.event.addListener(marker, 'dragend', function() { }); }